Vscode: Run Active File in Terminal menu should insert quotes for CMD

Created on 11 Feb 2020  路  11Comments  路  Source: microsoft/vscode

Issue Type: Bug

Ran VSC under 64-bit Windows 7 Pro with two hard drives (C: and D:). Loaded single-file program with Python Extension enabled, from folder with a space in its path (d:\Work\Code Stuff\Test). Inserted ${fileDirname} in Integrated: CWD box under Settings, which works fine selecting New Terminal menu item. Got this ouput when selecting Run Active File menu item,

Microsoft Windows [Version 6.1.7601]
Copyright (c) 2009 Microsoft Corporation. All rights reserved.

D:\Work\Code Stuff\Test>d:\Work\Code Stuff\Test\wavtrim.py
'd:\Work\Code' is not recognized as an internal or external command,
operable program or batch file.

D:\Work\Code Stuff\Test>

Obviously, the CWD inserted by VSC worked as expected, but the *.py command should have been wrapped in double quotes to accomodate spaces in my path, resulting in,

D:\Work\Code Stuff\Test>"d:\Work\Code Stuff\Test\wavtrim.py"
. . .

I verified this string works as expected when typed at a Command Prompt launched using Windows Explorer, after changing to my Test directory. Note that Run Without Debugging in the Debug menu works as expected -- it has no problems with directory change or program invocation.

VS Code version: Code 1.42.0 (ae08d5460b5a45169385ff3fd44208f431992451, 2020-02-06T10:51:34.058Z)
OS version: Windows_NT x64 6.1.7601


System Info

|Item|Value|
|---|---|
|CPUs|Intel(R) Core(TM) i5-6500 CPU @ 3.20GHz (4 x 3192)|
|GPU Status|2d_canvas: enabled
flash_3d: enabled
flash_stage3d: enabled
flash_stage3d_baseline: enabled
gpu_compositing: enabled
metal: disabled_off
multiple_raster_threads: enabled_on
oop_rasterization: disabled_off
protected_video_decode: unavailable_off
rasterization: enabled
skia_renderer: disabled_off
surface_control: disabled_off
surface_synchronization: enabled_on
video_decode: enabled
viz_display_compositor: enabled_on
viz_hit_test_surface_layer: disabled_off
webgl: enabled
webgl2: enabled|
|Load (avg)|undefined|
|Memory (System)|15.71GB (11.94GB free)|
|Process Argv|D:\Work\MEI Stuff\Test\wavtrim_main.py|
|Screen Reader|no|
|VM|0%|

Extensions (1)

Extension|Author (truncated)|Version
---|---|---
python|ms-|2020.1.58038


bug good first issue help wanted integrated-terminal verified

Most helpful comment

Hi,

Saw this issue labaled as "good first issue". I was looking to get into the project for a while now and this seems like a good place to start, so I would like to take it on if that's OK 馃榿

All 11 comments

This is Python: Run Active File? Please file at the Python extension: https://github.com/Microsoft/vscode-python

This Run Active File selection is in the main VSC Terminal menu. I assume
it would apply when attempting to run any program in the Windows CMD
terminal. There is nothing Python specific about this problem. Microsoft
provided the double-quote solution for referencing files with spaces in
their path quite some years ago.

My bad, reopening.

Hi,

Saw this issue labaled as "good first issue". I was looking to get into the project for a while now and this seems like a good place to start, so I would like to take it on if that's OK 馃榿

@dormesica sure, I haven't yet reproduced the bug personally but the code for this is located here:

https://github.com/microsoft/vscode/blob/802fdbac9f2aa6670fb426a59081737f4b22f91e/src/vs/workbench/contrib/terminal/browser/terminalService.ts#L473-L533

@Tyriar

I think I've reproduced the bug. I got this in my PowerShell:
bug

I encountered preparePathForTerminalAsync was tring to debug the RunActiveFileInTerminalAction. I'll take a look in there in the coming days.

I have confirmed that moving my Python code file to a folder with no spaces in the path does result in a valid CMD command and proper running of the code, with this output,

Microsoft Windows [Version 6.1.7601]
Copyright (c) 2009 Microsoft Corporation. All rights reserved.

D:\Work\Test>d:\Work\Test\wavtrim.py

@ Entering routine sDrive {generated by my program}

. . .

I do now see the green Run button in VSC that invokes the external Python interpreter (installed in Windows) to run my code in a CMD terminal. It wraps the path/filename argument in double quotes, with this output,

Microsoft Windows [Version 6.1.7601]
Copyright (c) 2009 Microsoft Corporation. All rights reserved.

C:\Users\General>C:/Python38/python.exe "d:/Work/Code Stuff/Test/wavtrim.py"

@ Entering routine sDrive {generated by my program}

. . .

I am not sure if this entry point is from core VSC or the Python Extension, but it may be worth a look at relevant VSC code.

Thanks for your interest in this issue!

Robb L.

@Tyriar After I've reproduced the bug I tried to debug it but it seemed to work fine.

It took me a while to reproduce it again. After I did I tried to run it again and again it worked fine (I haven't chaned anything). I got this as the output of the 2 attempts:
problem reproducing for github

I guess it is some kind of race-condition. Does this make sense?

@dormesica hmm, maybe it's a race condition if it's inconsistent?

@Tyriar For me it would happen once and then several times would work fine.

In the picture I've added earlier I wanted to show 2 consecutive attempts where in the first the bug occurred and in the second it didn't (obviously I didn't change anything between the 2 attempts, simply clicked on Run Active File).

@dormesica I can reproduce consistently, you need to kill all the terminal instances before launching the Run Active File action.
I think the issue is here
https://github.com/microsoft/vscode/blob/6ec6f9e3f4d17f0cef0480688a1f350b9141e567/src/vs/workbench/contrib/terminal/browser/terminalActions.ts#L688-L706
If there is no terminal a new one will be created with getActiveOrCreateInstance but this function returns before the instance.shellLaunchConfig.executable is defined so the preparePathForTerminalAsync does nothing because it's undefined

Was this page helpful?
0 / 5 - 0 ratings

Related issues

biij5698 picture biij5698  路  3Comments

shanalikhan picture shanalikhan  路  3Comments

mrkiley picture mrkiley  路  3Comments

curtw picture curtw  路  3Comments

villiv picture villiv  路  3Comments