Skip to content

Windows: Support running script files using process::Command #94743

Closed
@ChrisDenton

Description

@ChrisDenton

On Windows, currently only running .exe files is supported and script files aren't. Running .bat or .cmd (batch) files may work due to an undocumented feature of CreateProcessW (the underlying Windows API call) but it would be good to have proper, documented support rather than relying on undocumented features.

Implementing support for batch files would require finding cmd.exe ourselves and making sure the arguments passed to the batch file are interpreted as intended.

Supporting other types of script file may also be desirable. This can be done by examining the PATHEXT environment variable for a list of script file extensions. If the given script file has an extension that matches an entry in this list, then the registry can be used to look up the program to run it.

For example, getting the default value from HKEY_CLASSES_ROOT\.js will give the default id of the .js extension ("JSFile"). This id can be used to find the command by getting the default value from HKEY_CLASSES_ROOT\JSFile\Shell\open\command. This will return something like C:\Windows\System32\WScript.exe "%1" %* where %1 should be replaced with the full path to the script file and %* should be replaced with any arguments being passed to the script.

MSDN documentation

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-processArea: `std::process` and `std::env`C-feature-requestCategory: A feature request, i.e: not implemented / a PR.O-windowsOperating system: WindowsT-libsRelevant to the library team, which will review and decide on the PR/issue.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions