popen

Python subprocess Popen: Send binary data to C++ on Windows

孤街浪徒 提交于 2020-01-11 11:58:16
问题 After three days of intensive googleing and stackoverflowing I more or less got my program to work. I tried a lot of stuff and found a lot of answers somehow connected to my problem, but no working solution. Sry should I have missed the right page!! I'm looking forward to comments and recommendations. Task: Send binary data (floats) from python to C++ program, get few floats back Data is going to be 20ms soundcard input, latency is a bit critical Platform: Windows (only due to drivers for the

PHP Pipe into a background process

雨燕双飞 提交于 2020-01-11 07:31:11
问题 I'm trying to use popen to run a php script in the background. However, I need to pass a (fairly large) serialized object. $cmd = "php background_test.php >log/output.log &"; $fh = popen($cmd, 'w'); fwrite($fh, $data); fclose($fh); //pclose($fh); Without the ampersand this code executes fine but the parent script will wait until the child is finished running. With the ampersand STDIN gets no data. Any ideas? 回答1: As far as I know there is no way in php to send a process in background and

Python: How to peek into a pty object to avoid blocking?

爷,独闯天下 提交于 2020-01-10 15:33:01
问题 I am using pty to read non blocking the stdout of a process like this: import os import pty import subprocess master, slave = pty.openpty() p = subprocess.Popen(cmd, stdout = slave) stdout = os.fdopen(master) while True: if p.poll() != None: break print stdout.readline() stdout.close() Everything works fine except that the while-loop occasionally blocks. This is due to the fact that the line print stdout.readline() is waiting for something to be read from stdout . But if the program already

Python: How to peek into a pty object to avoid blocking?

我只是一个虾纸丫 提交于 2020-01-10 15:32:25
问题 I am using pty to read non blocking the stdout of a process like this: import os import pty import subprocess master, slave = pty.openpty() p = subprocess.Popen(cmd, stdout = slave) stdout = os.fdopen(master) while True: if p.poll() != None: break print stdout.readline() stdout.close() Everything works fine except that the while-loop occasionally blocks. This is due to the fact that the line print stdout.readline() is waiting for something to be read from stdout . But if the program already

Bash style process substitution with Python's Popen

我只是一个虾纸丫 提交于 2020-01-09 23:22:08
问题 In Bash you can easily redirect the output of a process to a temporary file descriptor and it is all automagically handled by bash like this: $ mydaemon --config-file <(echo "autostart: True \n daemonize: True") or like this: $ wc -l <(ls) 15 /dev/fd/63 see how it is not stdin redirection: $ vim <(echo "Hello World") vim opens a text file containing "Hello world" $ echo "Hello World" | vim Vim: Warning: Input is not from a terminal You can see in the second example how bash automatically

Bash style process substitution with Python's Popen

两盒软妹~` 提交于 2020-01-09 23:19:48
问题 In Bash you can easily redirect the output of a process to a temporary file descriptor and it is all automagically handled by bash like this: $ mydaemon --config-file <(echo "autostart: True \n daemonize: True") or like this: $ wc -l <(ls) 15 /dev/fd/63 see how it is not stdin redirection: $ vim <(echo "Hello World") vim opens a text file containing "Hello world" $ echo "Hello World" | vim Vim: Warning: Input is not from a terminal You can see in the second example how bash automatically

Is it possible to run function in a subprocess without threading or writing a separate file/script.

自古美人都是妖i 提交于 2020-01-08 19:40:47
问题 import subprocess def my_function(x): return x + 100 output = subprocess.Popen(my_function, 1) #I would like to pass the function object and its arguments print output #desired output: 101 I have only found documentation on opening subprocesses using separate scripts. Does anyone know how to pass function objects or even an easy way to pass function code? 回答1: I think you're looking for something more like the multiprocessing module: http://docs.python.org/library/multiprocessing.html#the

Is it possible to run function in a subprocess without threading or writing a separate file/script.

五迷三道 提交于 2020-01-08 19:40:32
问题 import subprocess def my_function(x): return x + 100 output = subprocess.Popen(my_function, 1) #I would like to pass the function object and its arguments print output #desired output: 101 I have only found documentation on opening subprocesses using separate scripts. Does anyone know how to pass function objects or even an easy way to pass function code? 回答1: I think you're looking for something more like the multiprocessing module: http://docs.python.org/library/multiprocessing.html#the

Python popen command. Wait until the command is finished

烈酒焚心 提交于 2020-01-08 11:33:30
问题 I have a script where I launch with popen a shell command. The problem is that the script doesn't wait until that popen command is finished and go continues right away. om_points = os.popen(command, "w") ..... How can I tell to my Python script to wait until the shell command has finished? 回答1: Depending on how you want to work your script you have two options. If you want the commands to block and not do anything while it is executing, you can just use subprocess.call . #start and block

Make Popen wait for first command to finish then start next

回眸只為那壹抹淺笑 提交于 2020-01-07 02:32:21
问题 I'm trying to run a program and feed the program a script as such: subprocess.Popen(['X:\\apps\\Nuke6.1v5\\Nuke6.1.exe', '-t', 'X:\\apps\\Scripts\NUKE\\nukeExternalControl\\server.py']) My problem is that it takes the program a few seconds to finish launching. So while its starting up the program Popen runs the next command and of course because the program is not up and running is errors out. So my question is how do I tell Popen to wait for the first application to run THEN execute the next