• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 147
  • Last Modified:

Take care of the output from system(...)

Hi
How do I take care of the output from the systemfunction.
Ex.
system("useradd -g users -d /home/.......");
Lets say it doesnt work and says something here. If it were in ordinary shellscript you could redirect the output to a logfile (>>logfile), but if I want perl to print it to a logfile.

Thanks
Classe
0
cl071997
Asked:
cl071997
  • 3
  • 2
  • 2
1 Solution
 
martinagCommented:
open(LOG, ">log.log") or die "can't open file: $!";
print LOG `useradd -g users -d /home/.......`; # Note the backticks!
close LOG;

Martin
0
 
cl071997Author Commented:
The example looks nice, but it doesn´t works. I tried it careully.
It do reports to STDOUT but doesn´t prints it to the LOG.

Try it, does it really work for you...I tried on both Linux and HP-UX.
Perl version 5.004_003.

Regards
Classe
0
 
martinagCommented:
Works great.
What is printed to the logfile? Nothing?

Martin
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
cl071997Author Commented:
Thats right - nothing...but the message comes to the screen (STDERR).


Classe
0
 
ozoCommented:
`useradd -g users -d /home/.......  2>&1`
0
 
cl071997Author Commented:
Offcourse...thanks alot !!!

Classe
0
 
ozoCommented:
see also
perldoc -q STDERR
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

  • 3
  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now