Sublime Forum

Python subprocess does not run as Plugin

#1

Hello Community,

I created a new Sublime Package with the following code:

import subprocess

subprocess.call(['echo', 'hello world'])

In ST console, I get the following output:

reloading plugin User.rubbish

If I run this code in a normal Python shell, I get the following output:

hello world
[Finished in 29ms]

I would expect to have the following output in ST console:

reloading plugin User.rubbish
hello world

Thanks in advance for any help.

0 Likes

#2

If your goal is to get the stdout / stderr / exit_code of a subprocess, and if you are using py38, you can do it like this https://github.com/jfcherng-sublime/ST-CommandAndMenu/blob/1880be345bcd456d0df786888dc02d2d3afa6d3c/plugin/commands/open_git_repo_on_web.py#L113-L123

1 Like

#3

Well, instead of call you could use check_output, which returns whatever was written to stdout by called process.

subprocess.check_output(['echo', 'hello world']).decode()
1 Like