os.system

Python threads with os.system() calls. Main thread doesn't exit on ctrl+c

吃可爱长大的小学妹 提交于 2020-01-01 10:57:15
问题 Please don't consider it a duplicate before reading, There are a lot of questions about multithreading and keyboard interrupt , but i didn't find any considering os.system and it looks like it's important. I have a python script which makes some external calls in worker threads. I want it to exit if I press ctrl+c But it look like the main thread ignores it. Something like this: from threading import Thread import sys import os def run(i): while True: os.system("sleep 10") print i def main():

passing more than one variables to os.system in python

為{幸葍}努か 提交于 2020-01-01 05:37:04
问题 I want to pass two variables to the os.system() for example listing files in different format in specific directory like (ls -l testdirectory) in which both a switch and test directory are variable. I know for single variable this one works: option=l os.sytem('ls -%s' option) but I dont know how to pass two variables? 回答1: you are asking about string formating (since os.system takes a string, not a list of arguments) cmd = "ls -{0} -{1}".format(var1,var2) #or cmd = "{0} -{1} -{2}".format("ls"

Need to use a variable in an os.system command in python

限于喜欢 提交于 2019-12-31 05:22:07
问题 I am new to python and I need to use a variable in the os.system command, here's my code so far import os , sys s = raw_input('test>') then i want to use the varable s in an os.system command so I was thinking something like os.system("shutdown -s -t 10 -c" 's') I don't want answers for that specific command I just want to know in general but if you are going to use an example use shutdown 回答1: then i want to use the varable s in an os.system Use string.format function. os.system("shutdown -s

How to stop another already running script in python?

女生的网名这么多〃 提交于 2019-12-28 16:18:13
问题 There is a way to start another script in python by doing this: import os os.system("python [name of script].py") So how can i stop another already running script? I would like to stop the script by using the name. 回答1: It is more usual to import the other script and then invoke its functions and methods. If that does not work for you, e.g. the other script is not written in such a way that is conducive to being imported, then you can use the subprocess module to start another process. import

Python os.system command not working?

こ雲淡風輕ζ 提交于 2019-12-25 02:58:43
问题 Earlier I used to code in python well, but after I formatted my computer and reinstalled the same python setup, my os.system command stopped working, as well as subprocess.Popen . 回答1: Looks like a path issue. The only way I could reproduce that -1 error was by setting my path to nothing so that Python couldn't find cmd.exe. Here's a link I ran across by searching for "set windows path" in stack exchange: http://support.microsoft.com/kb/310519 It tells how to set it for Winddows XP, the

os.system not working, but typing the same thing into the command prompt works

懵懂的女人 提交于 2019-12-23 18:53:16
问题 I am trying to run python abaqus through the command prompt using os.system('abaqus CAE noGUI=ODBMechens') It doesn't seem to run anything, but if I go to the command prompt myself and type in abaqus CAE noGUI=ODBMechens it works. I am using python 2.7 on Windows 10. Thanks 回答1: try using the subprocess module (it's newer) instead: for example, subprocess.call(["ls", "-l"]) and in your example, it would be: subprocess.call('abaqus CAE noGUI=ODBMechens') More info on the difference between

TypeError: must be string without null bytes, not str

六月ゝ 毕业季﹏ 提交于 2019-12-23 07:48:32
问题 I'm trying to run this code, to run the same command (with little changes) with every frame that I have: traj.reset() import os #os.chdir(outname) for i, frame in enumerate(traj): frame.superpose() comando = "python hollow.py -c constraint -o hollow_%s.pdb urei%s.pdb" % (i, i) os.system(comando) pml_cmd = "pymol urei%s.pdb hollow_%s.pdb -c -d 'as cartoon, urei%s;color gray90, urei%s;center chain A;set_view (\-0.605158150,0.089404292,0.791067421,\0.795849979,0.093013920,0.598304033,\-0

TypeError: must be string without null bytes, not str

旧巷老猫 提交于 2019-12-23 07:48:26
问题 I'm trying to run this code, to run the same command (with little changes) with every frame that I have: traj.reset() import os #os.chdir(outname) for i, frame in enumerate(traj): frame.superpose() comando = "python hollow.py -c constraint -o hollow_%s.pdb urei%s.pdb" % (i, i) os.system(comando) pml_cmd = "pymol urei%s.pdb hollow_%s.pdb -c -d 'as cartoon, urei%s;color gray90, urei%s;center chain A;set_view (\-0.605158150,0.089404292,0.791067421,\0.795849979,0.093013920,0.598304033,\-0

Wait for child using os.system

放肆的年华 提交于 2019-12-22 21:16:12
问题 I use a lot of os.system calls to create background processes inside a for loop. How can I wait for all the background processes to end ? os.wait tells me there are no child process. ps: I am using Solaris here is my code : #!/usr/bin/python import subprocess import os pids = [] NB_PROC=30 for i in xrange(NB_PROC): p = subprocess.Popen("(time wget http://site.com/test.php 2>&1 | grep real )&", shell=True) pids.insert(0,p) p = subprocess.Popen("(time wget http://site.com/test.php 2>&1 | grep

Wait for child using os.system

限于喜欢 提交于 2019-12-22 21:16:12
问题 I use a lot of os.system calls to create background processes inside a for loop. How can I wait for all the background processes to end ? os.wait tells me there are no child process. ps: I am using Solaris here is my code : #!/usr/bin/python import subprocess import os pids = [] NB_PROC=30 for i in xrange(NB_PROC): p = subprocess.Popen("(time wget http://site.com/test.php 2>&1 | grep real )&", shell=True) pids.insert(0,p) p = subprocess.Popen("(time wget http://site.com/test.php 2>&1 | grep