Here's a c routine that prints a single line :
#include <stdio.h>
main()
{
printf ("Hello World!\n");
}
And now the Python program (called 'po.py') that uses 'popen2' :
import popen2
(fin, fout) = popen2.popen2(r'c:\home\hw.exe', -1, 't')
print fin.readline()
fin.close()
fout.close()
When this is run it properly outputs the one line from the c routine :
C:\>python c:\python\po.py
Hello World!
Now here is my attempt to use the 'subprocess' module :
from subprocess import *
p = Popen(r'c:\home\hw.exe', bufsize=-1, stdin=PIPE, stdout=PIPE,
universal_newlines=True)
fin = p.stdin
print fin.readline()
fin.close()
When this is run, I get no output :
C:\>python c:\python\sp.py
C:\>
As you can see, I get no exception.
I've tried various combinations of the Popen arguments with no joy.
The platform is Windows XP Pro, so I did not try things like
'close_fds'.
What am I missing ?
Daniel Klein 3 2029
Daniel Klein wrote:
Here's a c routine that prints a single line :
#include <stdio.h>
main()
{
printf ("Hello World!\n");
}
And now the Python program (called 'po.py') that uses 'popen2' :
import popen2
(fin, fout) = popen2.popen2(r'c:\home\hw.exe', -1, 't')
print fin.readline()
fin.close()
fout.close()
When this is run it properly outputs the one line from the c routine :
C:\>python c:\python\po.py
Hello World!
Now here is my attempt to use the 'subprocess' module :
from subprocess import *
p = Popen(r'c:\home\hw.exe', bufsize=-1, stdin=PIPE, stdout=PIPE,
universal_newlines=True)
fin = p.stdin
print fin.readline()
fin.close()
When this is run, I get no output :
C:\>python c:\python\sp.py
C:\>
As you can see, I get no exception.
I've tried various combinations of the Popen arguments with no joy.
The platform is Windows XP Pro, so I did not try things like
'close_fds'.
What am I missing ?
Daniel Klein
subprocess will actually execute as a subprocess, so you have to wait
for the command to finish before you look at the stdout. Advantages of
this being that you can interfere with stdin/out whilst the program is
running. I believe .wait will be what you want, although i haven't look
at the docstring, so double check.
Daniel Klein wrote:
Now here is my attempt to use the 'subprocess' module :
from subprocess import *
p = Popen(r'c:\home\hw.exe', bufsize=-1, stdin=PIPE, stdout=PIPE,
universal_newlines=True)
fin = p.stdin
p.stdin is the *other* process' stdin. if you want to read things it
prints, read from p.stdout instead.
print fin.readline()
fin.close()
</F>
Thanks /F, that was it.
Dan
On Sat, 18 Nov 2006 15:03:30 +0100, Fredrik Lundh
<fr*****@pythonware.comwrote:
[snip]
>p.stdin is the *other* process' stdin. if you want to read things it prints, read from p.stdout instead.
>print fin.readline() fin.close()
</F>
This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: Diez B. Roggisch |
last post by:
Hi,
I'm using the popen2 module to communicate with the crm114 text
classificator. First I used to create a subprocess, feed the text to
classify to it, close the crm's stdin file and read the...
|
by: P |
last post by:
I've written a couple of apps that required
running a command and grabbing the output,
and I've found the existing interfaces problematic for this.
I think the proliferation of functions and...
|
by: Rembrandt Q Einstein |
last post by:
I am running an external command and I need to know a) when it is done
and b) what it wrote to both stdout and stderr. After a little
searching, I found the popen2 module and used the Popen3...
|
by: jb |
last post by:
Hi there:
I need help with popen2 usage. I am coding on Windows 2000 environment
and I am basically trying to run command line executable program that
accepts command line arguments from user....
|
by: mikem76 |
last post by:
How do I automatically redirect stdout and stderr when using os.popen2
to start a long running process. If the process prints a lot of stuff
to stdout it will eventually stop because it runs out...
|
by: mikem76 |
last post by:
Is there a way to get the process id when starting a process using
os.popen2 or os.popen3 on linux?
Mike
|
by: metaperl.etc |
last post by:
The following program does not work if you uncomment #lis =
+ list(args)
Evidently Python is opting for the nullary constructor list() as
opposed to the other one which takes a sequence....
|
by: Daniel Klein |
last post by:
I have a few Python programs that use popen2, and they work quite
nicely and dependably, so I don't really have any reason to change
them to use the new subprocess module...unless of course there...
|
by: Michael George Lerner |
last post by:
Hi,
(Python 2.5, OS X 10.4.10)
I have a program called pdb2pqr on my system. It is installed so that
"pdb2pqr" is in my path and looks like:
#\!/bin/zsh -f
/sw/share/pdb2pqr/pdb2pqr.py "$@"...
|
by: Kemmylinns12 |
last post by:
Blockchain technology has emerged as a transformative force in the business world, offering unprecedented opportunities for innovation and efficiency. While initially associated with cryptocurrencies...
|
by: Naresh1 |
last post by:
What is WebLogic Admin Training?
WebLogic Admin Training is a specialized program designed to equip individuals with the skills and knowledge required to effectively administer and manage Oracle...
|
by: Carina712 |
last post by:
Setting background colors for Excel documents can help to improve the visual appeal of the document and make it easier to read and understand. Background colors can be used to highlight important...
|
by: BLUEPANDA |
last post by:
At BluePanda Dev, we're passionate about building high-quality software and sharing our knowledge with the community. That's why we've created a SaaS starter kit that's not only easy to use but also...
|
by: Rahul1995seven |
last post by:
Introduction:
In the realm of programming languages, Python has emerged as a powerhouse. With its simplicity, versatility, and robustness, Python has gained popularity among beginners and experts...
|
by: Ricardo de Mila |
last post by:
Dear people, good afternoon...
I have a form in msAccess with lots of controls and a specific routine must be triggered if the mouse_down event happens in any control.
Than I need to discover what...
|
by: Johno34 |
last post by:
I have this click event on my form. It speaks to a Datasheet Subform
Private Sub Command260_Click()
Dim r As DAO.Recordset
Set r = Form_frmABCD.Form.RecordsetClone
r.MoveFirst
Do
If...
|
by: DizelArs |
last post by:
Hi all)
Faced with a problem, element.click() event doesn't work in Safari browser.
Tried various tricks like emulating touch event through a function:
let clickEvent = new Event('click', {...
|
by: F22F35 |
last post by:
I am a newbie to Access (most programming for that matter). I need help in creating an Access database that keeps the history of each user in a database. For example, a user might have lesson 1 sent...
| |