Output of a command line command 
Author Message
 Output of a command line command

Hello,

I would like to assign the result of a command to a variable.
Is there a way to do it on NT with PERL ?
Exemple:
    A = `ls`
    echo $A
display the result of the ls command
How can I do the same thing with PERL on NT without using a temporary
file like
system("dir > toto")?

Thanks in advance for your help

--
Jerome MAS
__________________________________________________________
Axlan 1 rue du Petit Robinson  Tel : +33 (0)1 34 58 71 30
78353 Jouy-en-Josas  FRANCE    Fax : +33 (0)1 34 58 71 49



Wed, 18 Jun 1902 08:00:00 GMT  
 Output of a command line command

Quote:

> Hello,

> I would like to assign the result of a command to a variable.

see perlfaq8: Why can't I get the output of a command with system()?

--
Bob

Sent via Deja.com http://www.deja.com/
Before you buy.



Wed, 18 Jun 1902 08:00:00 GMT  
 Output of a command line command


says...

Quote:
> I would like to assign the result of a command to a variable.
> Is there a way to do it on NT with PERL ?
> Exemple:
>     A = `ls`
>     echo $A
> display the result of the ls command
> How can I do the same thing with PERL on NT without using a temporary
> file like
> system("dir > toto")?

Here are several approaches to solving this problem:

1.  Read the documentation.  perlop: "Quote and Quote-Like Operators"

2.  Read the FAQ.  perlfaq8: "Why can't I get the output of a command
with system()?"

3.  Try an experiment.  Write your example shell program in Perl:

     $A = `ls`;
     print $A;

This works on my NT system because I have a POSIX command set installed.  
You might need to replace `ls` by `dir`.

Guess what the origin of this particular bit of Perl syntax is?

--
(Just Another Larry) Rosler
Hewlett-Packard Laboratories
http://www.hpl.hp.com/personal/Larry_Rosler/



Wed, 18 Jun 1902 08:00:00 GMT  
 Output of a command line command
Nothing else I hate worse then when someone post
a reply and tells you to go look at a faq or
a man page.

you are confusing the purpose of the system call

the system("command"); would only return a status
of the executed program

use this instead

$string = `command`;

the back quotes will allow you to execute the
command and capture the STDOUT.

VE9GLN


Quote:

> Hello,

> I would like to assign the result of a command
to a variable.
> Is there a way to do it on NT with PERL ?
> Exemple:
>     A = `ls`
>     echo $A
> display the result of the ls command
> How can I do the same thing with PERL on NT

without using a temporary
Quote:
> file like
> system("dir > toto")?

> Thanks in advance for your help

> --
> Jerome MAS

__________________________________________________________
Quote:
> Axlan 1 rue du Petit Robinson  Tel : +33 (0)1 34
58 71 30
> 78353 Jouy-en-Josas  FRANCE    Fax : +33 (0)1 34
58 71 49
> http://www.axlan.com


Sent via Deja.com http://www.deja.com/
Before you buy.



Wed, 18 Jun 1902 08:00:00 GMT  
 Output of a command line command

Quote:

> Nothing else I hate worse then when someone post
> a reply and tells you to go look at a faq or
> a man page.

Nothing I hate worse than someone (like you) who puts their reply at the
top of the message and what they are replying to at the bottom.

Oh, yes there is something I hate worse, someone (like you) who
encourages people to not read the documentation and encourages people to
post simple questions here instead.

Oh, and there is something I hate even worse than those two.  Someone
(like you) who posts a reply that ignores what was in the original
message.  The original poster already was using backticks instead of
system so your FAQ answer was completely pointless.

--
Jeff



Wed, 18 Jun 1902 08:00:00 GMT  
 Output of a command line command

Quote:
> Nothing else I hate worse then when someone post
> a reply and tells you to go look at a faq or
> a man page.

Aha, another candidate for the killfile stakes.

Quote:
> you are confusing the purpose of the system call

I'd suggest looking more closely at the text that you're
upside-down-quoting...

Quote:
> the system("command"); would only return a status
> of the executed program

Gosh, you got that right.  So why did you quote to all and
sundry the original question:

Quote:
> > Is there a way to do it on NT with PERL ?
> > Exemple:
> >     A = `ls`

, riddle me that?

Quite why the OP then blundered off into "system" we may never know,
if they're not prepared to read the documentation and FAQs.

When you gain experience, and learn to post to usenet properly, you'll
be able to appreciate more clearly the non-sequiturs that you're
creating in your presentation, and be able to correct them before
posting.  I'd predict (although I could be wrong about this) that you
will also by then have learned the value of FAQs.  Welcome to usenet,
the new user FAQs are at news.announce.newusers.



Wed, 18 Jun 1902 08:00:00 GMT  
 
 [ 6 post ] 

 Relevant Pages 

1. capturing command line error or output from `<command>`

2. Running Command Line Commands

3. executing commands, command-line vs. browser

4. command line commands from inside perl ?

5. RE : DIFFICULT: Can't execute system command from FVWM, but can from the command line

6. How to run a command at the command line

7. novice question: how import many lines of command output

8. Command line options Input >Output how?

9. command-line output re-direction in winNT

10. Unicode output in Command Line

11. SNMP PERL module / command-line output differ

 

 
Powered by phpBB® Forum Software