For Programmers: Free Programming Magazines  


Home > Archive > PERL Beginners > August 2005 > System, shell question









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author System, shell question
Steve Tran

2005-08-26, 6:56 pm

Hello

I am a beginner to perl and I have a question

if I want to use system or open or backticks to
execute a system command,
like system("$cmd arg1"); ( with system for instance)

and the $cmd which is a prog takes another program
called in arg1 , and that program(arg1) requires
STDIN,
and I need to redirect the output from $cmd into a
file
how can I make both happen ?

if I do system("$cmd arg1");
I can see my program waiting for input in STDOUT,but I
cant capture the STDOUT to proces later but when I add
system("$cmd arg1 >> out");

the program waits but the output from arg1 goes to
out.
Is there an easy way to accomplish both.

I would really appreciate any help
steve





__________________________________
Yahoo! Mail for Mobile
Take Yahoo! Mail with you! Check email on your mobile phone.
http://mobile.yahoo.com/learn/mail
Binish A R

2005-08-26, 6:56 pm

steve tran wrote:

>Hello
>
>I am a beginner to perl and I have a question
>
>if I want to use system or open or backticks to
>execute a system command,
>like system("$cmd arg1"); ( with system for instance)
>
>and the $cmd which is a prog takes another program
>called in arg1 , and that program(arg1) requires
>STDIN,
>and I need to redirect the output from $cmd into a
>file
>how can I make both happen ?
>
>if I do system("$cmd arg1");
>I can see my program waiting for input in STDOUT,but I
>cant capture the STDOUT to proces later but when I add
>system("$cmd arg1 >> out");
>
>the program waits but the output from arg1 goes to
>out.
>Is there an easy way to accomplish both.
>
>I would really appreciate any help
>steve
>
>
>
>
>
>__________________________________
>Yahoo! Mail for Mobile
>Take Yahoo! Mail with you! Check email on your mobile phone.
>http://mobile.yahoo.com/learn/mail
>
>
>

Although the question isn't clear to me, I think you are looking for pipes ...

open (FD, "|command arg1");

print FD "text from STDIN goes here";


and if you want to capture the output from this program, you can use ...

open(FD, "command arg1|");
@buf = <FD>;



--
*//binish//*

Get Thunderbird <http://www.mozilla.org/products/thunderbird/>


John W. Krahn

2005-08-27, 3:55 am

steve tran wrote:
> Hello


Hello,

> I am a beginner to perl and I have a question
>
> if I want to use system or open or backticks to
> execute a system command,
> like system("$cmd arg1"); ( with system for instance)
>
> and the $cmd which is a prog takes another program
> called in arg1 , and that program(arg1) requires
> STDIN,
> and I need to redirect the output from $cmd into a
> file
> how can I make both happen ?
>
> if I do system("$cmd arg1");
> I can see my program waiting for input in STDOUT,but I
> cant capture the STDOUT to proces later but when I add
> system("$cmd arg1 >> out");
>
> the program waits but the output from arg1 goes to
> out.
> Is there an easy way to accomplish both.


The same way that you would do it on the command line:

system( "$cmd < arg1 >> out" );



John
--
use Perl;
program
fulfillment
Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com