Page 1 of 1
possibilities in "C"
Posted: Fri Dec 10, 2004 2:06 am
by rm
is it possible for a program in C to execute an exe file. ??? ???
Re:possibilities in "C"
Posted: Fri Dec 10, 2004 3:08 am
by Solar
Code: Select all
#include <stdlib.h>
int rc = system( "path/to/app.exe" );
Re:possibilities in "C"
Posted: Sat Apr 16, 2005 4:17 pm
by erikgreenwald
system() can be an awfully dangerous call to make, as shell variables can be induced to alter the call... fork() and something from the exec() family (execl() or execv()) are easy and tend to be a wee bit safer
-Erik
Re:possibilities in "C"
Posted: Sun Apr 17, 2005 11:53 pm
by Solar
Yes, but that's POSIX API, not C. How do you know he's running on a machine with POSIX API, and that he's not interested in portability across platforms?
Re:possibilities in "C"
Posted: Mon Apr 18, 2005 3:15 am
by Candy
How is system("notepad.exe"); more portable?
Re:possibilities in "C"
Posted: Mon Apr 18, 2005 3:45 am
by Solar
Grrrr.... >:(
For all we know, he might be doing system("MyOtherApp").
Starting a new process can be done with Process.Start(), OpenExec(), StartExecutable(), or execl(), depending on your operating system / support libraries.
But it can be done with system() on any compliant C compiler in any environment.
Re:possibilities in "C"
Posted: Sat Apr 23, 2005 2:57 am
by DevL
Candy wrote:
How is system("notepad.exe"); more portable?
It isn't. Replacing the string with a header-defined constant (think EDITOR in this case) on the other hand would greatly aid portability...
Being the cross-platform and portability geek, I'll have to side with Solar on this one (surprise, surprise).
Re:possibilities in "C"
Posted: Sat Apr 23, 2005 9:04 am
by distantvoices
since when you two don't agree, eh? *rofl* sometimes it occurs to me to think you are kinda twins or so.
Re:possibilities in "C"
Posted: Sun Apr 24, 2005 3:33 am
by Solar
Thanks for the compliment. ;D
Re:possibilities in "C"
Posted: Sun May 01, 2005 7:59 pm
by rich_m
I was just thinkin that i could create somthing like multi-threading programs in 'C' usin this system(). but then it would'nt work in DOS if not for the windows start.exe
btw in my college they teach us to program using 16-bit compilers..TURBO C..
. How do I use vc++ ?(i've got .NET2003)
Re:possibilities in "C"
Posted: Mon May 02, 2005 12:55 am
by Solar
rich_m wrote:
I was just thinkin that i could create somthing like multi-threading programs in 'C' usin this system(). but then it would'nt work in DOS if not for the windows start.exe
That isn't multithreading, that is batch parallelism.
Multithreading is when several threads
cooperate. Your example can't give music.exe any input data beyond command line parameters, and the only output data is the return code. Anything beyond that would have to work with temporary files, and that defeats the whole purpose of multithreading - increased efficiency.
The POSIX function you want to look at is fork()... dunno what it's equivalent is in WinAPI.
Re:possibilities in "C"
Posted: Mon May 02, 2005 9:34 am
by Colonel Kernel
Using fork() doesn't qualify as multithreading either. IMO, "multithreading" implies multiple threads in the same process, sharing the same address space.
The Win32 equivalent of fork() is CreateProcess(), more or less. To create threads, the Win32 call is CreateThread(), but if you're using C or C++ you should use _beginthreadex() instead. It's a wrapper for CreateThread() that cleans up C/C++ run-time library bookkeeping structures when the thread terminates.
Re:possibilities in "C"
Posted: Tue May 03, 2005 11:03 am
by rich_m
Solar wrote:
That isn't multithreading, that is batch parallelism.
Guess i had the wrong impression of what multithreading meant(i thought it was just running a couple of programs simultaneously), thanks . btw i would like to know of 'a' good tutorial for c,c++ using 32bit compilers, i'm not sure if my request sounds weird, if it does my apologies.
Re:possibilities in "C"
Posted: Wed May 04, 2005 2:12 am
by Solar
Colonel Kernel is correct, of course - fork() does create a new
process, not a new
thread - however, that process starts with
all the data of the forking process, so you're a big step further than with system().
And I have to admit that I haven't written anything multithreading yet.
Running several programs in parallel, BTW, is called "multitasking" (as opposed to what DOS did).