Jump to content
  • Advertisement
Sign in to follow this  
corrington_j

using a linux shell command through c code

This topic is 4890 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Advertisement
corrington_j,

Use 'system' to do this. Its in the stdlib.h, and you can also read up more on it through the man page 'man system'

-brad

Share this post


Link to post
Share on other sites
Be aware that system() is seldom the best way to get things done. For example, there are standard C functions for making directories (mkdir), checking for file existence (stat/fstat/access), and executing commands (fork/exec).

Share this post


Link to post
Share on other sites
The system function should work on any OS, not just Linux.

Example:

#include <stdlib.h>

int main()
{
system("commandName");
return 0;
}


Share this post


Link to post
Share on other sites
Quote:
Original post by Dave Hunt
Be aware that system() is seldom the best way to get things done. For example, there are standard C functions for making directories (mkdir), checking for file existence (stat/fstat/access), and executing commands (fork/exec).

seconded. a bash shell is spawned inside your program, and if you want to parse the output you have to redirect to a file, which then needs to be opened...
and the dependencies (need the programs installed) which make it os dependent.

i don't mean to sound rude, but a shell script could do the job for what your doing.

Share this post


Link to post
Share on other sites
Quote:
Original post by Ainokea
The system function should work on any OS, not just Linux.

Example:
*** Source Snippet Removed ***


And for completeness, in C++:

#include <cstdlib>

int main()
{
std::system( "command name and arguments" );
using std::system;
//or using namespace std;
system( "command name and arguments" );
}


(I'm aware the OP said C)

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!