LinuxQuestions.org
Help answer threads with 0 replies.
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 03-08-2010, 12:22 PM   #1
golmschenk
Member
 
Registered: Nov 2009
Posts: 144

Rep: Reputation: 15
C - How to run an external exe with parameters


Specifically I'm trying to run xmacro from within a c program. If I were to run it from the terminal I would do it along the lines of
Code:
xmacroplay :0.0 < script_file.txt
, but I want to run it from my c program. I'm fine with my c program running it from the terminal if that's possible and easier but I'm guessing there must be a better way. How would I go about doing this? Thanks!
 
Old 03-08-2010, 12:36 PM   #2
alunduil
Member
 
Registered: Feb 2005
Location: San Antonio, TX
Distribution: Gentoo
Posts: 684

Rep: Reputation: 62
You have a few options with this one. The simplest is to use the system() function which as you said calls a shell script from in C. The others involve using the fork and exec families of calls and it all depends on what kind of communication you need as well as your performance needs.

Regards,

Alunduil
 
Old 03-09-2010, 03:12 PM   #3
golmschenk
Member
 
Registered: Nov 2009
Posts: 144

Original Poster
Rep: Reputation: 15
Great! Yeah the system() function will work. Thanks.
 
Old 03-09-2010, 04:07 PM   #4
MrCode
Member
 
Registered: Aug 2009
Location: Oregon, USA
Distribution: Arch
Posts: 864
Blog Entries: 31

Rep: Reputation: 148Reputation: 148
I realize that the OP has solved their problem, but I just wanted to point something out to other people who may be reading this thread.

Using the system() function is really only good practice if you don't intend for your program to be cross-platform. Since system() essentially just passes a string to the system shell for it to parse, then a program that has bash commands in a system() call will only work on systems that use bash as the main shell. The most obvious problem with this is that, well, not all systems use bash as their main command shell (especially not Windows), and so you'll get errors if you try to run the same program with the same system() calls on a system with a different CLI shell.

I'm not trying to criticize the OP's use of the function...if it's for something private, then that's fine. I was just pointing out that you really shouldn't use the function in all cases.

Last edited by MrCode; 03-09-2010 at 04:08 PM.
 
  


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
passing parameters from a unix shell prompt into a windows cmd.exe prompt nano2 Programming 1 09-01-2009 11:26 AM
samba compatibility with microsoft srvtools.exe (usrmgr.exe and srvmgr.exe) checkmate3001 Linux - Software 1 09-06-2008 05:08 AM
how to run .exe file as we run the samwe in windows chandrala13 Linux - Newbie 2 05-22-2008 05:30 AM
How do I run .run and .exe files? AAJJCC Linux - Newbie 8 03-24-2006 06:46 PM
SETUP.EXE/autorun.exe don't run in wine mst3kman Linux - Games 3 01-22-2006 02:20 PM

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

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