Hello all, My question is hopefully particular enough to not relate to any of the other ones that I've read. I'm wanting to use subprocess and multiprocessing to spawn a bunch of jobs serially and return the return code to me. The problem is that I don't want to wait() so I can spawn the jobs all at once, but I do want to know when it finishes so I can get the return code. I'm having this weird problem where if I poll() the process it won't run. It just hangs out in the activity monitor without running (I'm …

Member Avatar
Member Avatar
+0 forum 10

i am trying to recieve input from external text editor using python's `subprocess` but I am not sure why i am getting the error diff = subprocess.Popen('open(os.path.join(os.getcwd(), "foo.txt") "w")', stdout=subprocess.PIPE) pr = subprocess.Popen(sublime, stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=True, stdin=diff.stdout) pr.wait() if pr.returncode == 0: msg = pr.stdout.read() print msg er = pr.stderr.read() print er fo.close() diff = subprocess.Popen('open(os.path.join(os.getcwd(), "foo.txt") "w")', stdout=subprocess.PIPE) File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/subprocess.py", line 711, in __init__ errread, errwrite) File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/subprocess.py", line 1308, in _execute_child raise child_exception OSError: [Errno 2] No such file or directory any help would be appreciated..

Member Avatar
Member Avatar
+0 forum 7

Is there any way to start an application with python and count how much time does it take to completely load, any idea if I can do it with os.syste, or subprocess.Popen ?

Member Avatar
Member Avatar
+0 forum 5

/home/nikos/public_html/cgi-bin/metrites.py in () 217 template = htmldata + counter 218 elif page.endswith('.py'): => 219 htmldata = subprocess.check_output( '/home/nikos/public_html/cgi-bin/' + page ) 220 template = htmldata.decode('utf-8').replace( 'Content-type: text/html; charset=utf-8', '' ) + counter 221 htmldata undefined, subprocess = <module 'subprocess' from '/opt/python3/lib/python3.3/subprocess.py'>, subprocess.check_output = <function check_output>, page = 'files.py' /opt/python3/lib/python3.3/subprocess.py in check_output(timeout=None, *popenargs=('/home/nikos/public_html/cgi-bin/files.py',), **kwargs={}) 584 retcode = process.poll() 585 if retcode: => 586 raise CalledProcessError(retcode, process.args, output=output) 587 return output 588 global CalledProcessError = <class 'subprocess.CalledProcessError'>, retcode = 1, process = <subprocess.Popen object>, process.args = '/home/nikos/public_html/cgi-bin/files.py', output = b'Content-type: text/html; charset=utf-8\n\n<bod...n position 74: surrogates not allowed\n\n-->\n\n' CalledProcessError: Command '/home/nikos/public_html/cgi-bin/files.py' returned non-zero …

Member Avatar
Member Avatar
+0 forum 4

Hi I am trying to run a python script which has this code snippet: process = subprocess.Popen('./start_ws.pl') process.wait() os.system('make') The perl script started changes environmental variables and enters into new subshell. After entering into new subshell, the commands below script os.system('make') goes unnoticed.They get executed only if i exit from subshell(created by pl script). The system command 'make' is executable only in new subshell. I tried like, pid = os.fork() if pid > 0: os.wait() os.system('make clean') else: os.system('./start_ws.pl') Even this doesnt work. Kindly help me to run 'make' command in same env created by 'start_ws.pl' perl script.

Member Avatar
Member Avatar
+0 forum 1

This small code example shows you how to approach the beginning concept of an very simple "IDE" for Python.

Member Avatar
+0 forum 0

I'm trying to do something simple like get calc.exe to start minimized, but it's not happening. import subprocess import win32gui import win32con info = subprocess.STARTUPINFO() info.dwFlags |= subprocess.STARTF_USESHOWWINDOW info.wShowWindow = win32con.SW_SHOWMINIMIZED x = subprocess.Popen("calc.exe", startupinfo = info) It pops up the same as always, no matter what I provide for wShowWindow.

Member Avatar
Member Avatar
+0 forum 1

I've got an application that I call several times in a for loop using subprocess.call. Every time I call it, it starts minimized. I want it to be in a restored window. So what I've tried to do is get a handle on the window using win32gui.FindWindow. But in my current setup, FindWindow doesn't run until after the process is finished. from subprocess import call from os import getcwd from win32gui import FindWindow from win32gui import ShowWindow settings_files = list([file_1, file_2, file_3]) #this creates a command "%executable_path%\spider_3.0.exe /run" spider_app = "\"%s\" /run % ("join(getcwd(), "spider_3.0.exe")) while len(settings_files) != 0: current_settings_file …

Member Avatar
+0 forum 0

I'm trying to open a tex file from within python, tell the tex editor to run (manually you would press ctrl + T) and finally close the program. So far I can only figure out how to open and close the program. this is what I have so far... os.spawnv(os.P_WAIT, r"C:\Program Files\MiKTeX 2.9\miktex\bin\miktex-texworks.exe", ('miktex-texworks' , dir_dst + temp3 + temp2 + '.tex'))

Member Avatar
Member Avatar
+0 forum 4

Hi Guys, I'm new to python - how to execute dos2unix from python - subprocess.popen with shell = False ? >>> cmd = subprocess.Popen(["dos2unix","./FEED1/bin/*"], stdout=subprocess.PIPE) dos2unix: converting file ./FEED1/bin/* to UNIX format ... >>> dos2unix: problems converting file ./FEED1/bin/* All help appreciated.

Member Avatar
Member Avatar
+0 forum 4

Hi. I want to run some shell commands on linux machine with python Popen, for ex. "ping". How I can terminate the process, if it isn't finished normally in a given time? I've tried write some code, can anybody improve it or give some better idea? Any suggestions appreciated. Thanx. [CODE] wait_sec = 10 import time import subprocess wForceKill = True res = subprocess.Popen(self.command, shell=True, stdout=subprocess.PIPE, stderr=subprocess.STDOUT) for i in range(wait_sec): time.sleep(1.0) res.poll() if res.returncode != None: wForceKill = False break if wForceKill: res.terminate() print("Subprocess was killed!") res_out = res.communicate()[0] [/CODE]

Member Avatar
Member Avatar
+0 forum 1

Hi, I have a for-loop, and in each iteration I have to open a dos-command. I use the subprocess module for this: [code=python] fid1=open("test.txt", 'w') p=subprocess.Popen(args, stdout=fid1, stderr=subprocess.STDOUT, shell=True) fid1.close() [/code] The output of the dos-command is written to the txt-file, but I still need to terminate the process p. p.wait() returns 0, which is ok, but when I do p.terminate() I get: WindowsError: [Error 5] Access is denied The process isn't closed, and during the next iteration a new process is started. In a short time I have hundreds of un-terminated processes. Any ideas? Thanks in advance, (I tried …

Member Avatar
+0 forum 0

Hi guys, I need your help. I am using python to synchronize several c programs. For one of these programs I need a dynamic interaction. I know there are several option: I am interested in the simplest one becouse I am noob. Python code and C code have to exange data: python lunch the c program with some input, c code elaborate it and generate some results, these results have to be elaborated by the python code and new input will be delivered back to the c program. I cannot use subprocess.communicate(input) becouse it will wait the end of the …

Member Avatar
Member Avatar
+0 forum 5

Good day. I would need an advice about sys.stdout and sys.stderr. I use Python 2.6, on Windows XP SP3, but i think the question is the same for UNIX/ MAC computers. I tried all possible combinations before posting this message, so ANY advice would be great. I work with "subprocess" module. I call an application, and i want to save 3 things : the return code, the string that application prints on the screen and possibly the error message, BUT i also want to see the message LIVE, while the application prints it. I get exactly the 3 things i …

Member Avatar
Member Avatar
+0 forum 1

The End.