By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
432,463 Members | 774 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 432,463 IT Pros & Developers. It's quick & easy.

Help launching external program

P: 4
I need to know how to launch an external application using a parameter specified in my program. More specifically, the user enters a string, and my program will execute "cd <string>".

Anyone know how I can do this?
Aug 8 '07 #1
Share this Question
Share on Google+
6 Replies


Expert 10K+
P: 11,448
I need to know how to launch an external application using a parameter specified in my program. More specifically, the user enters a string, and my program will execute "cd <string>".

Anyone know how I can do this?
Suppose I enter the string "foo"; are you able to construct a string "cd foo"?
Hint: sprintf();

kind regards,

Jos
Aug 8 '07 #2

RRick
Expert 100+
P: 463
Once you figure out how to construct your command, you'll want to execute it using the "system" command. It's found in the C header file stdlib.h.
Aug 9 '07 #3

P: 4
Once you figure out how to construct your command, you'll want to execute it using the "system" command. It's found in the C header file stdlib.h.
I know how to append to strings and stuff, I just don't know how to properly use the system() function with a string of text. I know how to launch a program using something like 'system("/bin/ls');' but how do I do system("custom_string")? I tried a whole bunch of possible ways but none of them worked.

Thanks :).
Aug 9 '07 #4

weaknessforcats
Expert Mod 5K+
P: 9,197
Is this for Windows?? If so, use CreateProcess(). The system() function is only for light use.
Aug 9 '07 #5

P: 4
My program needs to be compatible with Linux and Windows.
Aug 11 '07 #6

weaknessforcats
Expert Mod 5K+
P: 9,197
My program needs to be compatible with Linux and Windows.
The system() arguments are OS defined and those of Windows won't work on Unix/Linux.

You will still need conditionally compiled code.

Maintaining compatibility between Linux/Unix/Windows for both 32-bit and 64-bit will be a nice trick since the fundamental types are not consistently changed, alignment is different, MS doesn't use ANS C++ on 64-bit, etc...
Aug 12 '07 #7

Post your reply

Sign in to post your reply or Sign up for a free account.