I want to run a python script which is located in "path=/home/user/code" in another python code by os.system, in linux. I run the following code and it runs well:
os.system("cd " path ";" "./update.py")
But I want to run the script without changing the current directory. So when I run the following code:
os.system("." path "/update.py")
I get an error that says: "./home/user/code/update.py not found"
How can I solve it?
CodePudding user response:
remove the "." at the start of the command.
By typing "./home/..." your are asking to python to search for a folder called "home" in the current directory. If you remove the ".", the path will be interpreted as absolute and it should work. You also might have to start the command by "python". So your final command will be
python /home/user/code/update.py
CodePudding user response:
to correct it:
os.system(path "/update.py")
so basically it will be like - os.system(/home/user/code/update.py)
