Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris
 
PerlMonks  

Re: retrieve the value of a system call in a non blocking mode

by flexvault (Monsignor)
on Dec 05, 2013 at 21:10 UTC ( [id://1065848]=note: print w/replies, xml ) Need Help??


in reply to Do not display the command result in the console (updated)

Welcome young_monk_love_perl,

On *nix try this at the command prompt:

perl -e '$v=qx/ls/;open $f,">","./file";print $f $v;'

What this one liner does is ask the system to list the files in the current directory and save in variable '$v'; opens a file(./file); and print the contents of variable '$v' to the file. You can use an editor to view the contents of the file.

That's a rough beginning, but Perl has so much more to offer -- so enjoy!

Regards...Ed

"Well done is better than well said." - Benjamin Franklin

Replies are listed 'Best First'.
Re^2: retrieve the value of a system call in a non blocking mode
by young_monk_love_perl (Novice) on Dec 05, 2013 at 22:33 UTC

    Hi Ed,

    I'm sorry I don't understand, should I add this line in my script or use it to execute the scrit ?

    Because I need to call this script from a other one and I don't know how to execute the line perl -e '$v=qx/ls/;open $f,">","./file";print $f $v;' this line into perl script

      young_monk_love_perl,

        I'm sorry I don't understand...

      My answer wasn't to write your code, but to help you learn to program with Perl. If you look up the 'qx' function you will find that it is a way to call the system and have the output returned to your script. If you tried perl -e '$v=qx/ls/;' you would have found that the output of the 'ls' system command did not display on your console. (One of your requirements). I then showed you how to save the results to a text file, and if you tried the code, you would learn that once you had the output of your command, you could use 'split' to create an array or with 'map' to build a hash or, or, or, ...

      Others have given you some good examples and ideas, and you should explore their suggestions as well.

      If this is a one time requirement, you may want to hire a Perl programmer ( see 'jobs.perl.org'). If this is a career opportunity for you, then this site has lots of information to help you become a better and better Perl programmer.

      Hope this helps.

      Regards...Ed

      "Well done is better than well said." - Benjamin Franklin

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1065848]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others wandering the Monastery: (7)
As of 2024-04-16 18:02 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found