Community
cancel
Showing results for 
Search instead for 
Did you mean: 
Highlighted
Community Manager
1,037 Views

python import error:-

Jump to solution

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()

____________________________________________________________________________________________________________

Tags (1)
0 Kudos

Accepted Solutions
Highlighted
Employee
32 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

0 Kudos
1 Reply
Highlighted
Employee
33 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

0 Kudos