View Full Version : runing cmd from C
rock freak
December 5th, 2005, 06:36 AM
hi there guys how would you run a external program in C lets take the windows cmd cos all windows machines sud have tht!!!
any ideas??
JamesA
December 5th, 2005, 06:43 AM
What do u mean? Do you mean sending direct commands to the OS using C?
system(); should work, such as in windows system("dir"); would send the command dir to cmd and return the results. for linux it would be system("ls"); etc.
I hope this is what your asking, if not, sorry for the waste of time.:D
rock freak
December 5th, 2005, 06:45 AM
i was more thinking of getting C to open another program, i wasnt to clear on what i ment there sorry
JamesA
December 5th, 2005, 06:49 AM
im not sure if there is another function in C to do this, but system should be able to work. It must also be said im not the most competant C coder, havn't programmed in it in a long time.
However, lets say the other program you want to run is in the directory
"C:\rockfreak\anotherprogram.exe"
then to run that in a C program would be system("C:\rockfreak\anotherprogram.exe");
i..think.. give it a try.
jerome bettis
December 5th, 2005, 05:10 PM
when did this become a windows forum lol ...
you'll need to use fork() and excevp()
this thread should help you get what you need: http://www.ubuntuforums.org/showthread.php?t=43562&highlight=fork
wmcbrine
December 5th, 2005, 05:24 PM
system() works almost everywhere (it's ANSI). It's not as sophisticated as fork()/exec(), but you probably don't need it to be.
popen() is also nice.
gord
December 5th, 2005, 06:53 PM
http://www.ubuntuforums.org/showthread.php?t=95533 has a nice simple version of howto do it, there are quite a few ways to skin a cat ;)
vBulletin® v3.8.7, Copyright ©2000-2012, vBulletin Solutions, Inc.