You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When you execute a program "foo" with spawnProcess, it will find "foo.exe" if it is a file in the PATH environment variable. However, it will not find programs with the ".bat" extension.
When searching for a program in PATH on windows, all files with an extension from the PATHEXT environment variable should be checked, i.e.
PATHEXT=.COM;.EXE;.BAT;.CMD;.VBS;.VBE;.JS;.JSE;.WSF;.WSH;.MSC
I've created a small program to demonstrate/reproduce this issue:
import std.file, std.process, std.stdio;
void main(string[] args)
{
if (args.length == 1)
runTest();
else
writeln("running from an exe!");
}
void runTest()
{
const runDir = "C:\\temp\\testworkdir";
const pathDir = "C:\\temp\\testpathdir";
if (!exists(runDir)) mkdir(runDir);
if (!exists(pathDir)) mkdir(pathDir);
chdir(runDir);
const thisExe = thisExePath();writefln("thisExePath is '%s'", thisExe);const tempExe = pathDir ~ "\\anexeprogram.exe";std.file.copy(thisExe, tempExe);environment["PATH"] = environment["PATH"] ~ ";" ~ pathDir;writefln("Added '%s' to path", pathDir);run(["anexeprogram", "recursive"]); // worksconst tempBat = pathDir ~ "\\abatprogram.bat";{ auto batFile = File(tempBat, "w"); batFile.writeln("@echo running from a bat file");}run(["abatprogram.bat"]); // worksrun(["abatprogram"]); // FAILSwritefln("Success!");
}
void run(string[] args)
{
writefln("Running %s", args);
auto p = spawnProcess(args);
assert(0 == wait(p));
}
The text was updated successfully, but these errors were encountered:
Since batch files are not executables, but interpreted by cmd.exe, you need to use spawnShell instead.
Or are you suggesting that files with extensions in PATHEXT should be treated in a similar way to Linux shell scripts with shebang lines in them? It's a bit messy to implement that. The Windows ShellExecuteW function will run non-executables, but it doesn't allow you to set environment variables. So it's not a generic replacement for CreateProcessW.
johnnymarler (@marler8997) reported this on 2020-02-09T03:33:42Z
Transfered from https://issues.dlang.org/show_bug.cgi?id=20571
CC List
Description
The text was updated successfully, but these errors were encountered: