1

Here is my simple batch script:

d:
cd D:/test_folder/test_project
start chrome -incognito http://localhost:19002
code .
expo start

the script only executes up to the code . line and then gives me a prompt. expo start is never run. What could be the problem? How can I continue the execution after the code . line?

EDIT: If I remove the code . line, the file works as intended.

VaibhavJoshi
  • 355
  • 2
  • 15
  • 2
    If you close `code`, once it has opened, it should also work! Your issue is that you're not closing `code`, or your command needs to be modified if you want to run the `expo` line before `code` has been closed. Why not use `start` again? – Compo Mar 11 '20 at 10:35
  • Batch files execute each line of code to its completion before moving on to execute the next line of code. As you can see in your current code, using the `START` command resolves that issue otherwise `CODE` would never execute because it would be waiting for `CHROME` to finish executing. – Squashman Mar 11 '20 at 14:27

3 Answers3

1

After going through a lot of posts, I found out that the way to open vs code is:

d:
cd D:/test_folder/test_project
start chrome -incognito http://localhost:19002
start "" code D:/test_folder/test_project
expo start

This works as required.

VaibhavJoshi
  • 355
  • 2
  • 15
1

You should use call:

call code .

The file run by "code ." is not really an executable but a .cmd/.bat. As discused in here. Running one batch file within another without call will stop execution.

0

The answer of VaibhavJoshi almost worked for me: a new cmd is started before the script ends, and I don't want this.

On my side, where code yields two results:

C:\> where code
C:\Users\MyUser\AppData\Local\Programs\Microsoft VS Code\bin\code
C:\Users\MyUser\AppData\Local\Programs\Microsoft VS Code\bin\code.cmd

To prevent a new cmd to be started on start "" code, I had to use the .exe directly:

set vscode="%localappdata%\Programs\Microsoft VS Code\Code.exe"

rem some other stuff ...

start "" %vscode% --folder-uri vscode-remote://ssh-remote+10.3.3.3/path/to/my/project

Worked like a charm, for local and remote projects.

NdFeB
  • 109
  • 12