Bug 15915 – std.process.execute throws an exception when using workDir and a relative path

Status
RESOLVED
Resolution
INVALID
Severity
normal
Priority
P1
Component
phobos
Product
D
Version
D2
Platform
x86_64
OS
Linux
Creation time
2016-04-12T10:30:00Z
Last change time
2016-04-12T13:11:47Z
Assigned to
nobody
Creator
atila.neves

Comments

Comment #0 by atila.neves — 2016-04-12T10:30:27Z
Comment #1 by atila.neves — 2016-04-12T10:32:43Z
It works if a file named foo/app is executed like so: import std.process; execute(["foo/app", ...]; But not if like this: execute(["./app", ...], env, config, maxOutput, "foo"); spawnProcessImpl throws an exception ("Not an executable file") saying the file isn't executable because it's looking for the wrong file; it doesn't take workDir into account.
Comment #2 by schveiguy — 2016-04-12T12:02:32Z
You are misunderstanding what workDir is. From the documentation: "The working directory for the new process. By default the child process inherits the parent's working directory." In other words, this is the directory the process is started in, not the directory to look for an executable.
Comment #3 by atila.neves — 2016-04-12T12:53:15Z
Then my understanding is correct; that's what I thought workDir was, the directory where the process is started in. However, I don't think the current implementation makes sense. There's already an if to check if the path has directory separators in it - if workDir is not "", I think what makes sense is to be relative to workDir. i.e. execute(["./foo"]); //look for ./foo execute(["./foo"], ..., "bar"); //look for bar/foo execute(["foo"]); //search path for foo execute(["foo", ..., "bar"); //search path for foo
Comment #4 by schveiguy — 2016-04-12T13:11:47Z
(In reply to Atila Neves from comment #3) > However, I don't think the current implementation makes sense. There's > already an if to check if the path has directory separators in it - if > workDir is not "", I think what makes sense is to be relative to workDir. I'm not sure what you mean. I don't see any code that examines the format of workDir. > execute(["./foo"]); //look for ./foo > execute(["./foo"], ..., "bar"); //look for bar/foo > execute(["foo"]); //search path for foo > execute(["foo", ..., "bar"); //search path for foo Look for foo in relation to the *current process* working directory, not the working directory for the *new process*. If you think about it a while, it would not make any sense to search for the executable based on the target's working directory. This would mean you could easily hijack the execute call by putting a correctly named file in the target directory.