Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

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

Posted on 1999-01-22
7
Medium Priority
?
145 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
Industry Leaders: 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 800 total points
ID: 1210249
see also
perldoc -q STDERR
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

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

Many time we need to work with multiple files all together. If its windows system then we can use some GUI based editor to accomplish our task. But what if you are on putty or have only CLI(Command Line Interface) as an option to  edit your files. I…
Checking the Alert Log in AWS RDS Oracle can be a pain through their user interface.  I made a script to download the Alert Log, look for errors, and email me the trace files.  In this article I'll describe what I did and share my script.
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

618 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