Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW
 
PerlMonks  

system commands

by sellmethis (Initiate)
on Sep 15, 2005 at 15:55 UTC ( [id://492302]=perlquestion: print w/replies, xml ) Need Help??

sellmethis has asked for the wisdom of the Perl Monks concerning the following question:

part of a program i'm working on implements this process:
system('type C:\temp.ml | ocaml > C:/output.txt');

i'm wondering if there is a way to open the process in such a way that it does not close at the end of the command. i would like to be able to continue piping in commands without having to re-send everything that was already passed through.

hope that makes sense.
thanks,
steve

Replies are listed 'Best First'.
Re: system commands
by socketdave (Curate) on Sep 15, 2005 at 16:09 UTC
    You can open a handle to a pipe, then print to the handle (*nix type example, but you get the idea):

    open(PIPE, '| /bin/cat') or die "Could not open PIPE\n"; print PIPE "test123\n"; print PIPE "test456\n"; close PIPE or die "Could not close PIPE\n";
Re: system commands
by graff (Chancellor) on Sep 15, 2005 at 16:24 UTC
    No, that doesn't entirely make sense. Maybe you could give some more detail about what else you really want to do besides that one command line? What's the ultimate goal?

    If you have the windows port of the bash shell, you could conceivably try something like this -- but I really don't know whether this would work:

    open SHELL, "| bash.exe" or die "can't open the shell: $!"; print SHELL "type C:/temp.ml | ocaml > C:/output.txt\n"; print SHELL "dir C:/output.txt\n"; # and so on...
    But whatever you're actually trying to accomplish, there are probably better ways to do it, by allowing your own perl script to do more of the work. For example:
    open TEMP, "C:/temp.ml" or die "C:/temp.ml: $!"; open CAML, "| ocaml > C:/output.txt" or die "can't run ocaml: $!"; while (<TEMP>) { print CAML } close CAML; open TXT, "C:/output.txt" or die "C:/output.txt: $!"; while (<TXT>) { # do other stuff }
    There are lots of ways to things like this, with minimal use of "system()".
Re: system commands
by ruoso (Curate) on Sep 15, 2005 at 17:48 UTC
    See 490699 for an example of a very similar situation...
    daniel
Re: system commands
by sgifford (Prior) on Sep 15, 2005 at 21:19 UTC
    I think you want IPC::Open2, which will let you open a pipe for both reading and writing. Then you can write your data into it and read the results directly. Make sure the script you're interacting with can support this, though; in particular, it shouldn't buffer its output.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://492302]
Approved by marto
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others wandering the Monastery: (5)
As of 2024-03-19 07:42 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found