Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Perl > Perl Misc > is it possible?

Reply
Thread Tools

is it possible?

 
 
Jerry Preston
Guest
Posts: n/a
 
      10-20-2004
I have been running a script out side Perl and having the data go into a
file:

system "$program $ID > id_list.dat";

Is it possible to redirect the output in ward?

$ID < system "$program $ID";

Thanks,

Jerry


 
Reply With Quote
 
 
 
 
Jürgen Exner
Guest
Posts: n/a
 
      10-20-2004
Jerry Preston wrote:
> I have been running a script out side Perl and having the data go
> into a file:
>
> system "$program $ID > id_list.dat";


Ok, so far so good.

> Is it possible to redirect the output in ward?
>
> $ID < system "$program $ID";


I am not sure at all what you are trying to achive (your description is
rather, hmmmm, unusual).

Are you simply trying to capture the output from your external program and
assign it to a variable? If yes, then you may want to have a look at the
documentation for the function that you are using, in particular the fourth
sentence in the third paragraph:
"[...] This is
*not* what you want to use to capture the output from a command,
for that you should use [...]"
Or just the FAQ:
" Why can't I get the output of a command with system()?"
Or plain old Google (yes, this question comes up a few times every month).

If you are looking for something else, then please accept my appologies, my
crystal ball must have malfunctioned.

jue


 
Reply With Quote
 
 
 
 
Matthew Braid
Guest
Posts: n/a
 
      10-20-2004
Jerry Preston wrote:
> I have been running a script out side Perl and having the data go into a
> file:
>
> system "$program $ID > id_list.dat";
>
> Is it possible to redirect the output in ward?
>
> $ID < system "$program $ID";
>
> Thanks,
>
> Jerry
>
>


Backticks:

$output = `$program $ID`;

Note that this only gets you STDOUT - stderr will not be caught. Backticks also
do not have the more secure forms like system's multiple-argument form.

MB
 
Reply With Quote
 
Jerry Preston
Guest
Posts: n/a
 
      10-20-2004
You are correct, I am trying to capture the output from your external
program and assign it to a variable.

I just tried:

@ID = ( "$program", "$ID" );
system( @ID );

and I get what was passed in "$program", "$ID".

Have I missed something?

Thanks,

Jerry

"Jürgen Exner" <(E-Mail Removed)> wrote in message
news:m_jdd.5900$5l3.1782@trnddc02...
> Jerry Preston wrote:
> > I have been running a script out side Perl and having the data go
> > into a file:
> >
> > system "$program $ID > id_list.dat";

>
> Ok, so far so good.
>
> > Is it possible to redirect the output in ward?
> >
> > $ID < system "$program $ID";

>
> I am not sure at all what you are trying to achive (your description is
> rather, hmmmm, unusual).
>
> Are you simply trying to capture the output from your external program and
> assign it to a variable? If yes, then you may want to have a look at the
> documentation for the function that you are using, in particular the

fourth
> sentence in the third paragraph:
> "[...] This is
> *not* what you want to use to capture the output from a

command,
> for that you should use [...]"
> Or just the FAQ:
> " Why can't I get the output of a command with system()?"
> Or plain old Google (yes, this question comes up a few times every month).
>
> If you are looking for something else, then please accept my appologies,

my
> crystal ball must have malfunctioned.
>
> jue
>
>



 
Reply With Quote
 
A. Sinan Unur
Guest
Posts: n/a
 
      10-20-2004
"Jerry Preston" <(E-Mail Removed)> wrote in
news:cl4jlu$7p$(E-Mail Removed):

[ Please do not top-post. If you don't know what this means, it is time for
you read the posting guidelines for this group. ]

> "Jürgen Exner" <(E-Mail Removed)> wrote in message
> news:m_jdd.5900$5l3.1782@trnddc02...
>> Jerry Preston wrote:
>> > I have been running a script out side Perl and having the data go
>> > into a file:
>> >
>> > system "$program $ID > id_list.dat";

>>
>> Ok, so far so good.
>>
>> > Is it possible to redirect the output in ward?
>> >
>> > $ID < system "$program $ID";

>>
>> I am not sure at all what you are trying to achive (your description
>> is rather, hmmmm, unusual).
>>
>> Are you simply trying to capture the output from your external
>> program and assign it to a variable? If yes, then you may want to
>> have a look at the documentation for the function that you are using,


> You are correct, I am trying to capture the output from your external
> program and assign it to a variable.


....

> Have I missed something?


Yes, reading the documentation, especially since Jürgen specifically
referred you to the section relevant to your request.

perldoc -f system

Sinan









>> in particular the

> fourth
>> sentence in the third paragraph:
>> "[...] This is
>> *not* what you want to use to capture the output from a

> command,
>> for that you should use [...]"
>> Or just the FAQ:
>> " Why can't I get the output of a command with system()?"
>> Or plain old Google (yes, this question comes up a few times every
>> month).
>>
>> If you are looking for something else, then please accept my
>> appologies,

> my
>> crystal ball must have malfunctioned.
>>
>> jue
>>
>>

>
>


 
Reply With Quote
 
James Willmore
Guest
Posts: n/a
 
      10-20-2004
Jerry Preston wrote:
> You are correct, I am trying to capture the output from your external
> program and assign it to a variable.
>
> I just tried:
>
> @ID = ( "$program", "$ID" );
> system( @ID );
>
> and I get what was passed in "$program", "$ID".
>
> Have I missed something?


<snip>
Yes.

(from `perldoc -q 'command'`)
=begin
How can I capture STDERR from an external command?

There are three basic ways of running external commands:

system $cmd; # using system()
$output = ‘$cmd‘; # using backticks (‘‘)
open (PIPE, "cmd │"); # using open()
=cut

`system` will get you the return code of the command being run.

(from `perldoc -f system`)
=begin

The return value is the exit status of the program as returned
by the "wait" call. To get the actual exit value shift right
by eight (see below). See also "exec". This is not what you
want to use to capture the output from a command, for that you
should use merely backticks or "qx//", as described in
"‘STRING‘" in perlop. Return value of -1 indicates a failure
to start the program (inspect $! for the reason).

=cut

The other two methods will get you the actual output from the command.

Execute the perldoc commands from above (or visit
http://www.perldoc.com/) for further information. If you're still
stuck, post again.

HTH

Jim
 
Reply With Quote
 
Jerry Preston
Guest
Posts: n/a
 
      10-20-2004
I read it! It still did not work!! I had to add ("./$program", "$ID" ).

Thanks,

Jerry

"A. Sinan Unur" <(E-Mail Removed)> wrote in message
news:Xns958871272E4asu1cornelledu@132.236.56.8...
> "Jerry Preston" <(E-Mail Removed)> wrote in
> news:cl4jlu$7p$(E-Mail Removed):
>
> [ Please do not top-post. If you don't know what this means, it is time

for
> you read the posting guidelines for this group. ]
>
> > "Jürgen Exner" <(E-Mail Removed)> wrote in message
> > news:m_jdd.5900$5l3.1782@trnddc02...
> >> Jerry Preston wrote:
> >> > I have been running a script out side Perl and having the data go
> >> > into a file:
> >> >
> >> > system "$program $ID > id_list.dat";
> >>
> >> Ok, so far so good.
> >>
> >> > Is it possible to redirect the output in ward?
> >> >
> >> > $ID < system "$program $ID";
> >>
> >> I am not sure at all what you are trying to achive (your description
> >> is rather, hmmmm, unusual).
> >>
> >> Are you simply trying to capture the output from your external
> >> program and assign it to a variable? If yes, then you may want to
> >> have a look at the documentation for the function that you are using,

>
> > You are correct, I am trying to capture the output from your external
> > program and assign it to a variable.

>
> ...
>
> > Have I missed something?

>
> Yes, reading the documentation, especially since Jürgen specifically
> referred you to the section relevant to your request.
>
> perldoc -f system
>
> Sinan
>
>
>
>
>
>
>
>
>
> >> in particular the

> > fourth
> >> sentence in the third paragraph:
> >> "[...] This is
> >> *not* what you want to use to capture the output from a

> > command,
> >> for that you should use [...]"
> >> Or just the FAQ:
> >> " Why can't I get the output of a command with system()?"
> >> Or plain old Google (yes, this question comes up a few times every
> >> month).
> >>
> >> If you are looking for something else, then please accept my
> >> appologies,

> > my
> >> crystal ball must have malfunctioned.
> >>
> >> jue
> >>
> >>

> >
> >

>



 
Reply With Quote
 
ChrisO
Guest
Posts: n/a
 
      10-20-2004
Matthew Braid wrote:
> Jerry Preston wrote:
>
>> I have been running a script out side Perl and having the data go into a
>> file:
>>
>> system "$program $ID > id_list.dat";
>>
>> Is it possible to redirect the output in ward?
>>
>> $ID < system "$program $ID";
>>
>> Thanks,
>>
>> Jerry
>>
>>

>
> Backticks:
>
> $output = `$program $ID`;
>
> Note that this only gets you STDOUT - stderr will not be caught.


my $rv = `$program $ID 2>&1`;

-ceo
 
Reply With Quote
 
Tad McClellan
Guest
Posts: n/a
 
      10-20-2004
Jerry Preston <(E-Mail Removed)> wrote:

> Subject: is it possible?



I am asking you again to please put the subject of your article
in the Subject of your article. Play nice!


> system "$program $ID > id_list.dat";
>
> Is it possible to redirect the output in ward?



Yes, and the documentation for system() tells you how to do that.

You should read the documentation for the functions that you use you know...


--
Tad McClellan SGML consulting
http://www.velocityreviews.com/forums/(E-Mail Removed) Perl programming
Fort Worth, Texas
 
Reply With Quote
 
Tad McClellan
Guest
Posts: n/a
 
      10-20-2004

[ Please do not top-post.
Text rearranged into a sensible order.
]


Jerry Preston <(E-Mail Removed)> wrote:
> "Jürgen Exner" <(E-Mail Removed)> wrote in message
> news:m_jdd.5900$5l3.1782@trnddc02...



>> Are you simply trying to capture the output from your external program and
>> assign it to a variable? If yes, then you may want to have a look at the
>> documentation for the function that you are using, in particular the

> fourth
>> sentence in the third paragraph:
>> "[...] This is
>> *not* what you want to use to capture the output from a

> command,
>> for that you should use [...]"
>> Or just the FAQ:
>> " Why can't I get the output of a command with system()?"



> You are correct, I am trying to capture the output from your external
> program and assign it to a variable.
>
> I just tried:
>
> @ID = ( "$program", "$ID" );



You have some useless uses of double quotes there.

perldoc -q vars

What's wrong with always quoting "$vars"?


> Have I missed something?



Yes, you missed reading the reply that you are following up to!

The docs that Jürgen pointed you to tell you how to do it, and it
isn't the way you've shown.

Why don't you just do it the way the docs say to?


--
Tad McClellan SGML consulting
(E-Mail Removed) Perl programming
Fort Worth, Texas
 
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




Advertisments