possibilities in "C"
Re:possibilities in "C"
Code: Select all
#include <stdlib.h>
int rc = system( "path/to/app.exe" );
Every good solution is obvious once you've found it.
Re:possibilities in "C"
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
-Erik
Re:possibilities in "C"
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?
Every good solution is obvious once you've found it.
Re:possibilities in "C"
How is system("notepad.exe"); more portable?
Re:possibilities in "C"
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.
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.
Every good solution is obvious once you've found it.
Re:possibilities in "C"
It isn't. Replacing the string with a header-defined constant (think EDITOR in this case) on the other hand would greatly aid portability...Candy wrote: How is system("notepad.exe"); more portable?
Being the cross-platform and portability geek, I'll have to side with Solar on this one (surprise, surprise).
-
- Member
- Posts: 1600
- Joined: Wed Oct 18, 2006 11:59 am
- Location: Vienna/Austria
- Contact:
Re:possibilities in "C"
since when you two don't agree, eh? *rofl* sometimes it occurs to me to think you are kinda twins or so.
... the osdever formerly known as beyond infinity ...
BlueillusionOS iso image
BlueillusionOS iso image
Re:possibilities in "C"
Thanks for the compliment. ;D
Every good solution is obvious once you've found it.
Re:possibilities in "C"
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)
Code: Select all
int n=system("start music.exe");
Re:possibilities in "C"
That isn't multithreading, that is batch parallelism.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
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.
Every good solution is obvious once you've found it.
- Colonel Kernel
- Member
- Posts: 1437
- Joined: Tue Oct 17, 2006 6:06 pm
- Location: Vancouver, BC, Canada
- Contact:
Re:possibilities in "C"
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.
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.
Top three reasons why my OS project died:
- Too much overtime at work
- Got married
- My brain got stuck in an infinite loop while trying to design the memory manager
Re:possibilities in "C"
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.Solar wrote: That isn't multithreading, that is batch parallelism.
Re:possibilities in "C"
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).
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).
Every good solution is obvious once you've found it.