Velocity Reviews

Velocity Reviews (http://www.velocityreviews.com/forums/index.php)
-   Perl Misc (http://www.velocityreviews.com/forums/f67-perl-misc.html)
-   -   is it possible? (http://www.velocityreviews.com/forums/t888599-is-it-possible.html)

Jerry Preston 10-20-2004 02:07 AM

is it possible?
 
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



Jürgen Exner 10-20-2004 02:23 AM

Re: is it possible?
 
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



Matthew Braid 10-20-2004 02:29 AM

Re: is it possible?
 
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

Jerry Preston 10-20-2004 02:48 AM

Re: is it possible?
 
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" <jurgenex@hotmail.com> 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
>
>




A. Sinan Unur 10-20-2004 04:02 AM

Re: is it possible?
 
"Jerry Preston" <g-preston1@ti.com> wrote in
news:cl4jlu$7p$1@home.itg.ti.com:

[ 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" <jurgenex@hotmail.com> 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
>>
>>

>
>



James Willmore 10-20-2004 04:20 AM

Re: is it possible?
 
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

Jerry Preston 10-20-2004 04:27 AM

Re: is it possible?
 
I read it! It still did not work!! I had to add ("./$program", "$ID" ).

Thanks,

Jerry

"A. Sinan Unur" <usa1@llenroc.ude.invalid> wrote in message
news:Xns958871272E4asu1cornelledu@132.236.56.8...
> "Jerry Preston" <g-preston1@ti.com> wrote in
> news:cl4jlu$7p$1@home.itg.ti.com:
>
> [ 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" <jurgenex@hotmail.com> 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
> >>
> >>

> >
> >

>




ChrisO 10-20-2004 04:27 AM

Re: is it possible?
 
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

Tad McClellan 10-20-2004 04:39 AM

Re: is it possible?
 
Jerry Preston <g-preston1@ti.com> 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
tadmc@augustmail.com Perl programming
Fort Worth, Texas

Tad McClellan 10-20-2004 04:43 AM

Re: is it possible?
 

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


Jerry Preston <g-preston1@ti.com> wrote:
> "Jürgen Exner" <jurgenex@hotmail.com> 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
tadmc@augustmail.com Perl programming
Fort Worth, Texas


All times are GMT. The time now is 04:31 PM.

Powered by vBulletin®. Copyright ©2000 - 2014, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.