communicate

Using Python to run executable and fill in user input

拈花ヽ惹草 提交于 2019-11-27 16:48:38
问题 I'm trying to use Python to automate a process that involves calling a Fortran executable and submitting some user inputs. I've spent a few hours reading through similar questions and trying different things, but haven't had any luck. Here is a minimal example to show what I tried last #!/usr/bin/python import subprocess # Calling executable ps = subprocess.Popen('fortranExecutable',shell=True,stdin=subprocess.PIPE) ps.communicate('argument 1') ps.communicate('argument 2') However, when I try

Python3 subprocess communicate example

↘锁芯ラ 提交于 2019-11-27 16:29:50
问题 I'm new to subprocessing. I just need a really simple win32 example of communicate() between a parent.py and child.py . A string sent from parent.py to child.py, altered by child.py and sent back to parent.py for print() from parent.py. I'm posting this because examples I have found end up either not being win32 or not using a child which just confuses me. Thanks for you help. 回答1: Here is a simple example as per your requirements. This example is Python 3.x (slight modifications are required

Communicating between two threads

只谈情不闲聊 提交于 2019-11-27 13:33:50
I have a thread, A which has a list. List holds some objects. Now I want to design a mechanisim by which I can send some message to thread A . Thread A runs in a loop (it does not wait or sleep). Some other thread, B , sends some message to thread A and thread A empties all its queues. How can I send messages between threads? class A extends Thread { List<Object> objs = something; //Init it void run() { while(true) { //Body which works on objects. //After receiving an external message, "A" should perform some action, for example, empty objects. } } } EDIT: Can I do it like this? class A

Capture “Segmentation fault” message for a crashed subprocess: no out and err after a call to communicate()

大兔子大兔子 提交于 2019-11-27 02:08:21
I have problems using the subprocess module to obtain the output of crashed programs. I'm using python2.7 and subprocess to call a program with strange arguments in order to get some segfaults In order to call the program, I use the following code: proc = (subprocess.Popen(called, stdout=subprocess.PIPE, stderr=subprocess.PIPE)) out,err=proc.communicate() print out,err called is a list containing the name of the program and the argument (a string containing random bytes except the NULL byte which subprocess doesn't like at all) The code behave and show me the stdout and stderr when the program

Capture “Segmentation fault” message for a crashed subprocess: no out and err after a call to communicate()

蹲街弑〆低调 提交于 2019-11-26 17:29:02
问题 I have problems using the subprocess module to obtain the output of crashed programs. I'm using python2.7 and subprocess to call a program with strange arguments in order to get some segfaults In order to call the program, I use the following code: proc = (subprocess.Popen(called, stdout=subprocess.PIPE, stderr=subprocess.PIPE)) out,err=proc.communicate() print out,err called is a list containing the name of the program and the argument (a string containing random bytes except the NULL byte

Communicating between two threads

不打扰是莪最后的温柔 提交于 2019-11-26 16:27:09
问题 I have a thread, A which has a list. List holds some objects. Now I want to design a mechanisim by which I can send some message to thread A . Thread A runs in a loop (it does not wait or sleep). Some other thread, B , sends some message to thread A and thread A empties all its queues. How can I send messages between threads? class A extends Thread { List<Object> objs = something; //Init it void run() { while(true) { //Body which works on objects. //After receiving an external message, "A"

Understanding Popen.communicate

喜欢而已 提交于 2019-11-26 15:18:19
I have a script named 1st.py which creates a REPL (read-eval-print-loop): print "Something to print" while True: r = raw_input() if r == 'n': print "exiting" break else: print "continuing" I then launched 1st.py with the following code: p = subprocess.Popen(["python","1st.py"], stdin=PIPE, stdout=PIPE) And then tried this: print p.communicate()[0] It failed, providing this traceback: Traceback (most recent call last): File "1st.py", line 3, in <module> r = raw_input() EOFError: EOF when reading a line Can you explain what is happening here please? When I use p.stdout.read() , it hangs forever.