digitalmars.D.learn - system vs. execvp ?
- Peter Sommerfeld (11/11) Sep 22 2012 Hi!
- Jonathan M Davis (13/29) Sep 22 2012 Please elaborate on what doesn't work as expected. We can't help you if ...
- Peter Sommerfeld (7/28) Sep 22 2012 Well, system(cmd) compiles xyz.d and creates an executable.
- Andrej Mitrovic (7/8) Sep 22 2012 string[] cmd;
- Jonathan M Davis (8/18) Sep 22 2012 Are you sure about that? That seems pretty messed up if that's the case....
- Jonathan M Davis (4/7) Sep 22 2012 The problem with the documentation has been reported:
- Andrej Mitrovic (3/4) Sep 22 2012 I was wrong, it's for a different reason:
Hi! This works as expected: string cmd = "dmd src/xyz.d"; int i = system(cmd); But this not: string[] cmd; cmd ~= "src/xyz.d"; int i = execvp("dmd",cmd); Of course, dmd is in PATH (Win7). What is wrong here? tia Peter
Sep 22 2012
On Sunday, September 23, 2012 00:53:48 Peter Sommerfeld wrote:Hi! This works as expected: string cmd = "dmd src/xyz.d"; int i = system(cmd); But this not: string[] cmd; cmd ~= "src/xyz.d"; int i = execvp("dmd",cmd); Of course, dmd is in PATH (Win7). What is wrong here?Please elaborate on what doesn't work as expected. We can't help you if you don't tell us what's wrong. system should run your command in a new process and return, whereas execvp will run it and never return, because the new process replaces your current one. Now, looking at the docs for std.process.execvp, they seem to think that the exec functions are going to return, but that's not what the man pages for the C functions (which they're calling) say, nor is it how they behave. Maybe that's your problem? http://linux.die.net/man/3/exec http://msdn.microsoft.com/en-us/library/3xw6zy53.aspx - Jonathan M Davis
Sep 22 2012
Jonathan M Davis wrote:Peter Sommerfeld wrote:Well, system(cmd) compiles xyz.d and creates an executable. execvp(cmd) does call dmd but that behaves as if no arguments where given (Usage msg etc). No executables are created.This works as expected: string cmd = "dmd src/xyz.d"; int i = system(cmd); But this not: string[] cmd; cmd ~= "src/xyz.d"; int i = execvp("dmd",cmd); Of course, dmd is in PATH (Win7). What is wrong here?Please elaborate on what doesn't work as expected. We can'thelp you if you don't tell us what's wrong.system should run your command in a new process and return,whereas execvp will run it and never return, because the new process replaces your current one.I did not know that it does not return. Anyway, it should compile the args IMHO but it does not. Peter
Sep 22 2012
On 9/23/12, Peter Sommerfeld <noreply rubrica.at> wrote:What is wrong here?string[] cmd; cmd ~= "dmd"; cmd ~= "src/xyz.d"; int i = execvp("dmd",cmd); 1st arg should always be the app name, even though apps typically ignore/skip the first arg.
Sep 22 2012
On Sunday, September 23, 2012 01:12:34 Andrej Mitrovic wrote:On 9/23/12, Peter Sommerfeld <noreply rubrica.at> wrote:Are you sure about that? That seems pretty messed up if that's the case. Yes, the first element in the argument list that main gets is the name of the program, but it's pretty messed up if any of the exec* functions require that you give the program name as the first argument rather than it being appropriately added by that program before its main is called. I'd be very surprised if you were correct about this. - Jonathan M DavisWhat is wrong here?string[] cmd; cmd ~= "dmd"; cmd ~= "src/xyz.d"; int i = execvp("dmd",cmd); 1st arg should always be the app name, even though apps typically ignore/skip the first arg.
Sep 22 2012
On Saturday, September 22, 2012 16:10:11 Jonathan M Davis wrote:Now, looking at the docs for std.process.execvp, they seem to think that the exec functions are going to return, but that's not what the man pages for the C functions (which they're calling) say, nor is it how they behave.The problem with the documentation has been reported: http://d.puremagic.com/issues/show_bug.cgi?id=8708 - Jonathan M Davis
Sep 22 2012
On 9/23/12, Jonathan M Davis <jmdavisProg gmx.com> wrote:I'd be very surprised if you were correct about this.I was wrong, it's for a different reason: http://stackoverflow.com/questions/3027320/why-first-arg-to-execve-must-be-path-to-executable
Sep 22 2012