is it possible?

J

Jerry Preston

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

Jürgen Exner

Jerry said:
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
 
M

Matthew Braid

Jerry said:
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
 
J

Jerry Preston

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 said:
Jerry said:
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

A. Sinan Unur

[ 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. ]
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
 
J

James Willmore

Jerry said:
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
 
J

Jerry Preston

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

Thanks,

Jerry

A. Sinan Unur said:
[ 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. ]
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
 
T

Tad McClellan

Jerry Preston said:
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...
 
T

Tad McClellan

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


Jerry Preston said:
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?
 
A

A. Sinan Unur

I read it!

You read what?
It still did not work!!

What did not work?
I had to add ("./$program", "$ID" ).

Huh?

Please stop top-posting and go ahead andread the posting guidelines. That
way, you might learn how to ask a question. You might also put some effort
into understanding responses to your posts. Your original question has been
answered by Jürgen Exner, James Willmore and Matthew Braid. Yet you keep on
posting gibberish.

Sinan.
 
A

Arndt Jonasson

James Willmore said:
(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()

I don't know about others, but I'm getting some strange binary
sequences above, where according to "perldoc -q command", when I run
it, there should be simple backquotes and vertical bars. Just thought
I'd point it out.
 
J

James Willmore

Arndt said:
I don't know about others, but I'm getting some strange binary
sequences above, where according to "perldoc -q command", when I run
it, there should be simple backquotes and vertical bars. Just thought
I'd point it out.

My newsreader and me are having a bit of a disagreement. I didn't
realize that the last post was sent with garbage. Sorry.

Jim
 
S

Sherm Pendley

Arndt said:
I don't know about others, but I'm getting some strange binary
sequences above, where according to "perldoc -q command", when I run
it, there should be simple backquotes and vertical bars. Just thought
I'd point it out.

According to my news client, the post you're referring to is encoded as
UTF-8, whereas yours is ISO-8859-1. Your news reader apparently doesn't
like UTF-8.

sherm--
 
R

Ron Parker

According to my news client, the post you're referring to is encoded as
UTF-8, whereas yours is ISO-8859-1. Your news reader apparently doesn't
like UTF-8.

Backtick is part of plain ASCII. Some brain-damaged so-called email clients
instead use a character in the private-use range in Unicode. If those
were really backticks, their ISO-8859-1 and UTF-8 representations would have
been identical.

http://www.fourmilab.ch/webtools/demoroniser/
 
B

Ben Morrow

Quoth Matthew Braid said:
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.

....but grep perlipc for 'safe backtick' for how emulate them safely.

Ben
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,576
Members
45,054
Latest member
LucyCarper

Latest Threads

Top