• How to Convert This Command into Python Code?
    2 replies, posted
Hello everybody, I have a question. There is a console command that I want to convert into python code. Here's the story. I compiled a command to turn USB hub on/off by following this page Turning usb ports on and off Basically what I did is: Copy the source code of hub-ctrl.c to my Raspberry Pi Change into the directory where the hub-ctrl.c code was copied Compile it into an executable named hub-ctrl (note the lack of a .c) Copy the compiled executable to the root directory Change back into the root directory Now I can run the newly compiled hub-ctrl command, by running this code in console: sudo ./hub-ctrl -h 0 -P 2 -p 0 ; sleep 5; sudo ./hub-ctrl -h 0 -P 2 -p 1; Which turns off USB hubs for 5 seconds, and restart it. It works fine. But, I want to run that code in Python. So, I did this in Python so I can use console commands in Python code: from subprocess import call call(["sudo", "./hub-ctrl", "-h", "0", "-P", "2", "-p", "0", ";", "sleep", "5;", "sudo", "./hub-ctrl", "-h", "0", "-P", "2", "-p", "1;"]) But it will not work. It will give an error sudo: ./hub-ctrl: command not found How can I run that command from the newly made excutable in Python code? How should I modify that to make it work? Any other method? Thanks in advance. Appreciate any help
I'm guessing the script doesn't have the current working directory that you think it has. Try putting in an explicit cd into the right directory first in your script
I see. How should I rephrase the Python code bit after I put the hub-ctrl file in the same directory as the Python code file?
Sorry, you need to Log In to post a reply to this thread.