Solved

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

Posted on 1999-01-22
7
142 Views
Last Modified: 2010-03-05
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
Comment
Question by:cl071997
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
  • 2
7 Comments
 
LVL 4

Expert Comment

by:martinag
ID: 1210243
open(LOG, ">log.log") or die "can't open file: $!";
print LOG `useradd -g users -d /home/.......`; # Note the backticks!
close LOG;

Martin
0
 

Author Comment

by:cl071997
ID: 1210244
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
 
LVL 4

Expert Comment

by:martinag
ID: 1210245
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!

 

Author Comment

by:cl071997
ID: 1210246
Thats right - nothing...but the message comes to the screen (STDERR).


Classe
0
 
LVL 84

Expert Comment

by:ozo
ID: 1210247
`useradd -g users -d /home/.......  2>&1`
0
 

Author Comment

by:cl071997
ID: 1210248
Offcourse...thanks alot !!!

Classe
0
 
LVL 84

Accepted Solution

by:
ozo earned 200 total points
ID: 1210249
see also
perldoc -q STDERR
0

Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

On Microsoft Windows, if  when you click or type the name of a .pl file, you get an error "is not recognized as an internal or external command, operable program or batch file", then this means you do not have the .pl file extension associated with …
A year or so back I was asked to have a play with MongoDB; within half an hour I had downloaded (http://www.mongodb.org/downloads),  installed and started the daemon, and had a console window open. After an hour or two of playing at the command …
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…

726 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question