Executing batch script via command line hangs #5229

Closed
opened 2026-01-31 00:08:06 +00:00 by claunia · 4 comments
Owner

Originally created by @mu88 on GitHub (Nov 27, 2019).

Environment

Windows build number: Microsoft Windows [Version 10.0.18362.476]
Windows Terminal version: 0.7.3291.0

Steps to reproduce

  1. Configure a profile with a batch file like this:
"name" : "Build MyApp",
"guid" : "{65869F08-7651-44A5-9EAB-982A1577BC65}",
"commandline" : "Batch\\Build.MyApp.bat",
"startingDirectory" : "C:\\Projects\\MyApp",
"closeOnExit" : false,
"fontFace" : "Fira Code",
"fontSize" : 10,
"icon" : "C:\\Projects\\MyApp\\MyApp.ico"
  1. Execute the profile Build MyApp

Expected behavior

The batch file C:\Projects\MyApp\Batch\Build.MyApp.bat will be executed.

Actual behavior

A new tab will be opened, but nothing gets executed. It is hanging:
image

Originally created by @mu88 on GitHub (Nov 27, 2019). <!-- 🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨 I ACKNOWLEDGE THE FOLLOWING BEFORE PROCEEDING: 1. If I delete this entire template and go my own path, the core team may close my issue without further explanation or engagement. 2. If I list multiple bugs/concerns in this one issue, the core team may close my issue without further explanation or engagement. 3. If I write an issue that has many duplicates, the core team may close my issue without further explanation or engagement (and without necessarily spending time to find the exact duplicate ID number). 4. If I leave the title incomplete when filing the issue, the core team may close my issue without further explanation or engagement. 5. If I file something completely blank in the body, the core team may close my issue without further explanation or engagement. All good? Then proceed! --> <!-- This bug tracker is monitored by Windows Terminal development team and other technical folks. **Important: When reporting BSODs or security issues, DO NOT attach memory dumps, logs, or traces to Github issues**. Instead, send dumps/traces to secure@microsoft.com, referencing this GitHub issue. If this is an application crash, please also provide a Feedback Hub submission link so we can find your diagnostic data on the backend. Use the category "Apps > Windows Terminal (Preview)" and choose "Share My Feedback" after submission to get the link. Please use this form and describe your issue, concisely but precisely, with as much detail as possible. --> # Environment ```none Windows build number: Microsoft Windows [Version 10.0.18362.476] Windows Terminal version: 0.7.3291.0 ``` # Steps to reproduce 1. Configure a profile with a batch file like this: ``` "name" : "Build MyApp", "guid" : "{65869F08-7651-44A5-9EAB-982A1577BC65}", "commandline" : "Batch\\Build.MyApp.bat", "startingDirectory" : "C:\\Projects\\MyApp", "closeOnExit" : false, "fontFace" : "Fira Code", "fontSize" : 10, "icon" : "C:\\Projects\\MyApp\\MyApp.ico" ``` 2. Execute the profile `Build MyApp` # Expected behavior The batch file `C:\Projects\MyApp\Batch\Build.MyApp.bat` will be executed. # Actual behavior A new tab will be opened, but nothing gets executed. It is hanging: ![image](https://user-images.githubusercontent.com/4560672/69708959-d2a43000-10fc-11ea-8bd2-c76ea570da78.png)
claunia added the Issue-QuestionNeeds-Tag-FixResolution-AnsweredProduct-Terminal labels 2026-01-31 00:08:06 +00:00
Author
Owner

@zadjii-msft commented on GitHub (Nov 27, 2019):

@mu88 what if you set the commandline to cmd.exe /k Batch\\Build.MyApp.bat? I think you need the cmd.exe /k to tell it to actually run cmd.exe with the batch script you've specified.

@zadjii-msft commented on GitHub (Nov 27, 2019): @mu88 what if you set the `commandline` to `cmd.exe /k Batch\\Build.MyApp.bat`? I think you need the `cmd.exe /k` to tell it to actually run cmd.exe with the batch script you've specified.
Author
Owner

@mu88 commented on GitHub (Nov 27, 2019):

@zadjii-msft That actually solved my issue. Thank you very much! Do you have any idea why that popped up after upgrading Windows Terminal to the latest version?

@mu88 commented on GitHub (Nov 27, 2019): @zadjii-msft That actually solved my issue. Thank you very much! Do you have any idea why that popped up after upgrading Windows Terminal to the latest version?
Author
Owner

@zadjii-msft commented on GitHub (Nov 27, 2019):

Honestly I don't think it should have ever worked in the first place tbh. If I had to guess, it's because we changed from using conhost directly to using the pseudoconsole API properly. With the conhost backend, conhost would try and create the process on our behalf, but I guess it was able to CreateProcess a bat file? Then when we switched to conpty, we started creating the child process ourself, and maybe we weren't as liberal with what we could create.

/cc @DHowett-MSFT for visibility, because he likes these kinds of issues

@zadjii-msft commented on GitHub (Nov 27, 2019): Honestly I don't think it should have ever worked in the first place tbh. If I had to guess, it's because we changed from using `conhost` directly to using the pseudoconsole API properly. With the conhost backend, conhost would try and create the process on our behalf, but I guess it was able to `CreateProcess` a bat file? Then when we switched to conpty, we started creating the child process ourself, and maybe we weren't as liberal with what we could create. /cc @DHowett-MSFT for visibility, because he likes these kinds of issues
Author
Owner

@DHowett-MSFT commented on GitHub (Nov 27, 2019):

The real issue here is that of the working directory. 😄

The profile specifies a commandline of Batch\Build.MyApp.bat with a starting directory. When we were launching through conhost, we would launch conhost in the starting directory. When conhost went to launch Build.MyApp.bat, CreateProcess started searching relative to conhost's CWD.

Now that we're handing starting directory directly to the process we're spawning, instead of having an intermediate process change to that folder first, all commandlines will need to be either fully-qualified or supported by %PATH%.

TL;DR: Set the commandline to the full path to the batch file, or keep asking cmd to intervene (since we're starting cmd in the right folder, then asking cmd to find the batch file.)

@DHowett-MSFT commented on GitHub (Nov 27, 2019): The real issue here is that of the _working directory_. :smile: The profile specifies a commandline of `Batch\Build.MyApp.bat` with a starting directory. When we were launching through conhost, we would launch conhost in the starting directory. When conhost went to launch `Build.MyApp.bat`, CreateProcess started searching relative to conhost's CWD. Now that we're handing starting directory directly to the process we're spawning, instead of having an intermediate process change to that folder first, all commandlines will need to be either fully-qualified or supported by `%PATH%`. TL;DR: Set the commandline to the full path to the batch file, or keep asking cmd to intervene (since we're starting cmd in the right folder, then asking cmd to find the batch file.)
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/terminal#5229