LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 06-14-2005, 12:30 AM   #1
Quantum0726
Member
 
Registered: Dec 2003
Location: Milwaukee, WI
Distribution: Gentoo
Posts: 39

Rep: Reputation: 15
Running shell script within a C or C++ program


Hi, I have a shell script that I'd like to execute from within a C++ program. For example, I need to access the man command, the redirection operator, and a command that converts a ps file to a pdf. If I can run my bash script from within a C++ binary this would take care of it. So would running each command from within the C++ program. I could also probably do this in C, but I'm not as familiar with C as I am with C++.

Thanks much!
 
Old 06-14-2005, 12:42 AM   #2
uman
Member
 
Registered: Sep 2004
Distribution: Gentoo
Posts: 134

Rep: Reputation: 15
Make sure you've included cstdlib.

then do this:

system("name-of-command");

if your batch file is in the path you can do

system("name-of-your-batch-file");

system(const char*); basically runs an executable.
 
Old 06-15-2005, 09:14 PM   #3
Quantum0726
Member
 
Registered: Dec 2003
Location: Milwaukee, WI
Distribution: Gentoo
Posts: 39

Original Poster
Rep: Reputation: 15
Thanks, that worked great!
 
  


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
Starting a program from a shell script Suinatsa Programming 2 04-17-2005 12:16 AM
running a program from shell script Suinatsa Programming 10 04-14-2005 11:25 AM
Communication between shell script and program ZooL Programming 6 08-14-2004 05:44 AM
run shell script in c program u4u Linux - General 1 02-14-2004 02:48 PM
c/c++ running a shell script? thermalpants Programming 3 05-12-2002 11:41 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 11:42 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