tinycc-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Fw: [Tinycc-devel] windows resources LinkRes2Exe.exe by Mike Henning


From: Rob Landley
Subject: Re: Fw: [Tinycc-devel] windows resources LinkRes2Exe.exe by Mike Henning
Date: Thu, 5 Oct 2006 16:10:46 -0400
User-agent: KMail/1.9.1

On Thursday 05 October 2006 3:28 pm, Laurens Simonis wrote:
> D_FONT),RT_RCDATA);
>  > and at finally it worked!!! thank you very much!!
>  > to all, how does one code a c program that knows its executable name and
>  > can restart itself?
> 
> 
> The executable name can be found in argv[0] I think. Starting an exe can 
> be done with system();
> 
> #include <stdio.h>
> 
> int main(int argc, char **argv)
> {
>    printf(argv[0]);
>    return 0;
> }

That's a little oversimplified.  The path isn't reliably in there, and the 
executable might not be in $PATH.  On linux, you can exec /proc/self/exe and 
expect it to work.  (I don't do Windows.)

Also, system() washes stuff through "/bin/sh", which spawns an extra process 
and it's a child process rather than a restart.  On Linux you want one of the 
exec() family of calls (man exec).  Possibly execvp();

Rob
-- 
Never bet against the cheap plastic solution.




reply via email to

[Prev in Thread] Current Thread [Next in Thread]