digitalmars.D.bugs - [Issue 20571] New: spawnProcess does not find .bat files
- d-bugmail puremagic.com (58/58) Feb 08 2020 https://issues.dlang.org/show_bug.cgi?id=20571
https://issues.dlang.org/show_bug.cgi?id=20571 Issue ID: 20571 Summary: spawnProcess does not find .bat files Product: D Version: D2 Hardware: x86 OS: Windows Status: NEW Severity: enhancement Priority: P1 Component: phobos Assignee: nobody puremagic.com Reporter: johnnymarler gmail.com 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"]); // works const tempBat = pathDir ~ "\\abatprogram.bat"; { auto batFile = File(tempBat, "w"); batFile.writeln(" echo running from a bat file"); } run(["abatprogram.bat"]); // works run(["abatprogram"]); // FAILS writefln("Success!"); } void run(string[] args) { writefln("Running %s", args); auto p = spawnProcess(args); assert(0 == wait(p)); } --
Feb 08 2020