Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Opening VS Code from 'cmd.exe' and then trying to immediately exit command window fails. #6608

Closed
maptz opened this issue May 21, 2016 · 7 comments
Assignees
Labels
*question Issue represents a question, should be posted to StackOverflow (VS Code) windows VS Code on Windows issues
Milestone

Comments

@maptz
Copy link

maptz commented May 21, 2016

  • VSCode Version:1.1.1
  • OS Version:Windows 10

I want to open VS Code from a command line, and exit the command window in one step, but for some reason this fails.

Steps to Reproduce:

  1. Open a command window, cmd.exe
  2. Type in: start "" code . && exit
  3. VS Code opens, the command window closes, but immediately re-opens.

The equivalent command start "" notepad && exit works as expected.

@bpasero bpasero assigned joaomoreno and unassigned bpasero May 22, 2016
@maptz maptz changed the title Opening VS Code from 'cmd.exe' and then trying to immediately exiting command window fails. Opening VS Code from 'cmd.exe' and then trying to immediately exit command window fails. May 22, 2016
@joaomoreno
Copy link
Member

Unfortunately code is a batch script in itself, while nodepad is an executable.

What are you trying to achieve here? Doesn't a simple code . return immediately?

@joaomoreno joaomoreno added the info-needed Issue requires more information from poster label May 24, 2016
@maptz
Copy link
Author

maptz commented May 24, 2016

I am trying to end Command Window bloat when I'm editing files. I want to open a command terminal to start VS Code and then close the command window once Code is open.

For instance, I have full VS running, and want to edit the same solution in VSCode, I press Ctrl+Alt+Space (my key-binding for opening command terminals in full VS.) Then I want to type in some command to open VS Code at the current location, and close the newly opened command window. Note: If I type code . and press enter, code will open, and hijack the focus, so I can't type exit immediately which means I have to navigate back to the opening command window to type an 'exit' command.

I have found that I can get the desired behaviour if I change LINE 5 of the code.cmd file to:

 start` "" "%~dp0..\Code.exe" "%~dp0..\resources\\app\\out\\cli.js" %*

I can then type code . && exit to get the desired behaviour.

I'm not a batch script expert, so I don't really understand the consequences of starting code using start versus call. No doubt it has consequences.

@joaomoreno
Copy link
Member

Me neither... it is truly a dark craft...

We can explore using start instead of call... see what breaks in there.

@joaomoreno joaomoreno added this to the June 2016 milestone May 24, 2016
@joaomoreno joaomoreno added bug Issue identified by VS Code Team member as probable bug and removed info-needed Issue requires more information from poster labels May 24, 2016
@maptz
Copy link
Author

maptz commented May 24, 2016

Great.

After very cursory research here, it appears that there is very little difference between CALL and START when initializing EXEs, and the differences only become relevant when starting (other) batch files.

@Tyriar
Copy link
Member

Tyriar commented May 25, 2016

I don't understand why code . returns immediately, so does code . & echo test, but code . & exit or code . && exit waits until vscode terminates...?

@joaomoreno
Copy link
Member

joaomoreno commented Jul 21, 2016

@maptz Figured out why call is used: it allows us to implement the --wait and companion command line switches. Using start would make the prompt return immediately at all times, even when using --wait, which would be wrong.

After one hour of trial and error, I failed to get anywhere.

Closing the issue since this is not specific to Code, but a Batch question. I suggest Stack Overflow for this. Good luck!

@joaomoreno joaomoreno added *question Issue represents a question, should be posted to StackOverflow (VS Code) and removed bug Issue identified by VS Code Team member as probable bug labels Jul 21, 2016
@Matheus-de-Souza
Copy link

Matheus-de-Souza commented Jun 14, 2017

I wrote a script to start vscode and other programs too, and I had the same problem @maptz had. I don't know why is used call instead of start "". Changing the line 5 on the code.cmd allowed me to start the vscode on cmd, powershell, etc..

@vscodebot vscodebot bot locked and limited conversation to collaborators Nov 17, 2017
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
*question Issue represents a question, should be posted to StackOverflow (VS Code) windows VS Code on Windows issues
Projects
None yet
Development

No branches or pull requests

5 participants