LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices


Reply
  Search this Thread
Old 01-21-2011, 03:59 AM   #1
mja
LQ Newbie
 
Registered: Feb 2010
Posts: 2

Rep: Reputation: 0
execute a linux command in the c program


I am trying to execute a limux command in c program using system system call, but the dont want it to dump the output or error logs on the terminal. What should I do? Is there any other way to do this?
 
Old 01-21-2011, 04:39 AM   #2
Dark_Helmet
Senior Member
 
Registered: Jan 2003
Posts: 2,786

Rep: Reputation: 374Reputation: 374Reputation: 374Reputation: 374
It depends on whether your program needs the output of the command you run.

If you don't need the output, then redirect stdout and stderr for the command. Say, for instance, you need to run a system script (/usr/local/do_something) to start a program. You would execute it like so:
Code:
system("/usr/local/do_something >/dev/null 2>&1")
If your program does need the output, then you can use the popen() function. You should be able to read about it with man popen.
 
1 members found this post helpful.
Old 01-25-2011, 10:44 PM   #3
mja
LQ Newbie
 
Registered: Feb 2010
Posts: 2

Original Poster
Rep: Reputation: 0
thanks for the answer..
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
C program code to execute linux-command supermichou_fr Linux - Software 4 08-01-2012 08:25 AM
Execute command upon every string that gets outputed from a program Tomás Ó hÉilidhe Linux - General 7 12-05-2008 04:04 AM
want to execute edquota command inside a c program admirelinux Linux - Newbie 3 11-10-2008 11:11 PM
Execute a linux command using a java program tvalenzuela Programming 2 10-07-2005 11:59 AM
execute command when program closes frieza Linux - Software 3 11-17-2003 05:51 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 08:24 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration