Vscode-code-runner: Incomplete output displayed and [Done] exited with code=null

Created on 30 Aug 2017  Â·  16Comments  Â·  Source: formulahendry/vscode-code-runner

When running a program with lots of console output, I'm getting a "[Done] exited with code=null in 0.0XX seconds" before all of the output has actually been written to the console.

Below is a simple Python3 example to reproduce the problem. Each time the code is run, the console output will enumerate to a different count value before it stops with the code=null exit code.

for count in range(100000):
    print(count)

The output window displays...

...
37345
37346
37347
37348
37349
37
[Done] exited with code=null in 0.044 seconds

If I run the same example in the Visual Studio Code terminal window, the full expected output is displayed every time.

bug

Most helpful comment

I'm not a Javascript/NodeJS programmer, but I did some reading of the code in this extension, as well as the NodeJS API, and think I may have come across something interesting.

I see that the exec() fucntion of child_process is being used in the executeCommandInOutputChannel() function in the codeManager.ts file. I'm understanding that exec() spawns a shell and executes the command within that shell, buffering any generated output. There is a maxBuffer option that is documented as:

maxBuffer \

https://nodejs.org/api/child_process.html#child_process_child_process_exec_command_options_callback

It looks as though the spawn() function should be used instead, since the data is streamed as standard IO objects -- not buffered strings.

All 16 comments

For quick turnaround, you could use below setting (File->Preference->Settings) to run code in Integrated Terminal:

{
    "code-runner.runInTerminal": true
}

Also, you may try below setting to run:

{
    "code-runner.executorMap.python": "python -u"
}

Are those options working for you?

Same issue, and the first option works.

{
    "code-runner.runInTerminal": true
}

The first option suggested successfully displays every print statement in the example above in the Terminal window, every time.

// First option
{
    "code-runner.runInTerminal": true
}

The second option suggested has the original issue displayed in the Output window.

// Second option
{
    "code-runner.executorMap.python": "python -u"
}

I'm not a Javascript/NodeJS programmer, but I did some reading of the code in this extension, as well as the NodeJS API, and think I may have come across something interesting.

I see that the exec() fucntion of child_process is being used in the executeCommandInOutputChannel() function in the codeManager.ts file. I'm understanding that exec() spawns a shell and executes the command within that shell, buffering any generated output. There is a maxBuffer option that is documented as:

maxBuffer \

https://nodejs.org/api/child_process.html#child_process_child_process_exec_command_options_callback

It looks as though the spawn() function should be used instead, since the data is streamed as standard IO objects -- not buffered strings.

Also, you may try below setting to run:

{
    "code-runner.executorMap.python": "python -u"
}

Are those options working for you?

You Could Make It
"code-runner.executorMap": { "python":"clear; python3 -u" }
For Python3/3.6 With A Clear Terminal Output.

@formulahendry

Thanks Man.
BTW, What's The Actual Problem Here ?

I'm Facing A Similar Problem Where The Code Just Goes On And On . . . And Only When I Click Ctrl+Alt+M Does The Execution Stop.

[Running] python "/home/yahyaa/Desktop/a.py"  //Goes On Till The Keys Are Pressed

[Done] exited with code=null in 1.766 seconds

Same problem in PHP!

First option works too...

Same problem python vsc windows 10

First option works. Thanks for the answer. 👌

This issue can lead to pretty nasty problems (debugging-wise) if one decides to e.g. create some output files and print some lengthy message about it on stout in the same loop. What happens is, SILENTLY, some of the files will go missing. Consider the below Python example:

for i in range(1, 4501):
    prefix = "debug/vscodetest/"
    suffix = ".txt"
    path = "{}{}{}".format(prefix, str(i), suffix)
    with open(path, mode="w") as f:
        f.write("Hello world!")

    print("#{} file printed {}".format(str(i), "padding"*3))

It only takes to change padding*3 to padding*4 to have couple hundred files gone missing. Have a good time noticing it, let alone trying to figure out what happened (especially considering these rather aren't gonna be some helloworlds in a simple range() loop).

In my case I first thought it was some strange problem with Python (performance issue, stout redirection I used not working properly etc.), then that it probably is some strange problem with VS Code and at last after one day at work spent on this I finally landed here.

I think the problem at least merits some more visibility (maybe its own separate issue?)

The same have happened to me, but in my case after applying your suggestions (_specially the one of running Python script in the Terminal_), I can see the starting point of the output

Hello, can anybody help me please. When i'm running terminal, i 've got very long details in terminal. How can i remove it, just to have the result of code
thank you in advance
terminal3

wanna have like this one
terminal2

Did Oleg Hwang get an answer to this question as I have same question exactly and can only find the question and no answer?

If you run the code in the terminal then it works. Usually, it is a buffer issue and your terminal will have a larger buffer.

First option works

For quick turnaround, you could use below setting (File->Preference->Settings) to run code in Integrated Terminal:

{
    "code-runner.runInTerminal": true
}

Also, you may try below setting to run:

{
    "code-runner.executorMap.python": "python -u"
}

Are those options working for you?

Works for VS code running python; note further that the output window was not printing in a 'co-moving' fashion so I couldn't see the output as it went along. Thanks.

@formulahendry could you take a look at https://github.com/formulahendry/vscode-code-runner/pull/428?

Fixed in v0.9.13. Thanks @JeffreyCA !!

Was this page helpful?
0 / 5 - 0 ratings