Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > Virtual file for subprocess

Reply
Thread Tools

Virtual file for subprocess

 
 
bobnotbob
Guest
Posts: n/a
 
      12-11-2009
I am calling external executable from my python program (using
subprocess). This external program's output is a text file which I
then read and parse. Is there any way to "sandbox" the calling of
this external program so that it writes to a virtual file instead of
the hardcoded text?
 
Reply With Quote
 
 
 
 
Lie Ryan
Guest
Posts: n/a
 
      12-11-2009
On 12/12/2009 4:07 AM, bobnotbob wrote:
> I am calling external executable from my python program (using
> subprocess). This external program's output is a text file which I
> then read and parse. Is there any way to "sandbox" the calling of
> this external program so that it writes to a virtual file instead of
> the hardcoded text?


If the program writes its outputs to the stdout, you can redirect the
program's stdout using subprocess, try to find a switch that will tell
it to write to stdout. Otherwise, you're pretty much stuck to using a
real file AFAIK.
 
Reply With Quote
 
 
 
 
Grant Edwards
Guest
Posts: n/a
 
      12-11-2009
On 2009-12-11, Lie Ryan <(E-Mail Removed)> wrote:
> On 12/12/2009 4:07 AM, bobnotbob wrote:
>> I am calling external executable from my python program (using
>> subprocess). This external program's output is a text file which I
>> then read and parse. Is there any way to "sandbox" the calling of
>> this external program so that it writes to a virtual file instead of
>> the hardcoded text?

>
> If the program writes its outputs to the stdout, you can
> redirect the program's stdout using subprocess, try to find a
> switch that will tell it to write to stdout. Otherwise, you're
> pretty much stuck to using a real file AFAIK.


Most Unix systems have paths that you can pass to programs
which think they need to write to "files". Accessing those
files actually access already open file descriptors such as
stdin, stdout, and stderr.

On Linux, for example, you can tell the program to write to
/proc/self/fd/1 and that's actually stdout which can then be a
pipe connected to the Python program that invoked the program.

This can be very useful when executing a program which can be
told what file to write to, but who's author was too
narrow-minded to provide the option to send output to stdout.

If you need to get fancy you can create multiple input/output
pipes that are inherited by the child program and then
references as /proc/self/fd/<whatever>.

--
Grant Edwards grante Yow! These PRESERVES should
at be FORCE-FED to PENTAGON
visi.com OFFICIALS!!
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: Print file via file association using os.system or subprocess?(Windows) python@bdurham.com Python 0 07-19-2010 01:49 AM
how to import subprocess into my 'subprocess.py' file hiral Python 2 05-05-2010 12:56 PM
[Subprocess/Windows] subprocess module under Windows 98 Andreas Jung Python 2 11-02-2005 05:41 PM
virtual template and virtual access for ADSL circuits Gary Cisco 1 04-28-2005 07:26 PM
Virtual Computer Corporation (VCC) Virtual Workbench VW300 Derek Simmons VHDL 0 08-01-2004 04:55 AM



Advertisments