Intel® Makers
Intel® Edison, Intel® Joule™, Intel® Curie™, Intel® Galileo
Announcements
Welcome - This is a Peer-to-Peer Forum only. Intel has discontinued these products but you may find support from other customers on this Forum
9867 Discussions

python import error:-

idata
Community Manager
1,113 Views

Hello everyone,

I'm trying to run a program which uses keyboard event.

basically i want to run specific bash script when I press a particular key.

my python program name is "command.py"

when I press "F" key then first bash script "first.sh" should run.

when I press "S" key then second bash script "second.sh" should run.

 

but it returns an error:

 

ImportError: No module named msvcrt

 

msvcrt is for windows and not for python so now what should i do to take keyboard key pressed ??

 

 

 

my program is like below:

 

____________________________________________________________________________________________________________

 

# !/usr/bin/python

import threading

import msvcrt

import subprocess

class myThread (threading.Thread):

def __init__(self, name):

threading.Thread.__init__(self)

self.name = name

def run(self):

process(self.name)

def process(threadname):

identity=threadname

if(identity=="first"):

# if second.sh is running, then kill second.sh & start first.sh

killall second.sh

subprocess.call("first.sh")

elif(identity=="operation"):

# if first.sh is running, then kill second.sh & start first.sh

killall first.sh

subprocess.call("second.sh")

# Create new threads

thread1 = myThread("first")

thread2 = myThread("second")

# Start new Threads

thread1.start()

thread2.start()

____________________________________________________________________________________________________________

0 Kudos
1 Solution
Carlos_M_Intel
Employee
108 Views

Hi Falak,

Have you tried with call systems instead of using subprocess, something like:

import os

code = os.system('sh /home/root/first.sh')

Regards,

Charlie

View solution in original post

1 Reply
Carlos_M_Intel
Employee
109 Views

Hi Falak,

Have you tried with call systems instead of using subprocess, something like:

import os

code = os.system('sh /home/root/first.sh')

Regards,

Charlie

View solution in original post

Reply