?
Solved

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

Posted on 1999-01-22
7
Medium Priority
?
144 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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 

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 800 total points
ID: 1210249
see also
perldoc -q STDERR
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

I have been pestered over the years to produce and distribute regular data extracts, and often the request have explicitly requested the data be emailed as an Excel attachement; specifically Excel, as it appears: CSV files confuse (no Red or Green h…
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…
Six Sigma Control Plans

752 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