How do I hide the console when I use os.system() or subprocess.call()?
I wrote some statements like below:
os.system(cmd) #do something
subprocess.call('taskkill /F /IM exename.exe')
both will pop up a console.
How can I stop it from popping up the console?
python windows console subprocess
add a comment |
I wrote some statements like below:
os.system(cmd) #do something
subprocess.call('taskkill /F /IM exename.exe')
both will pop up a console.
How can I stop it from popping up the console?
python windows console subprocess
Try usingspawn
family instead.
– Keith
Aug 10 '11 at 5:23
related: Running a process in pythonw with Popen without a console
– jfs
May 22 '14 at 0:47
add a comment |
I wrote some statements like below:
os.system(cmd) #do something
subprocess.call('taskkill /F /IM exename.exe')
both will pop up a console.
How can I stop it from popping up the console?
python windows console subprocess
I wrote some statements like below:
os.system(cmd) #do something
subprocess.call('taskkill /F /IM exename.exe')
both will pop up a console.
How can I stop it from popping up the console?
python windows console subprocess
python windows console subprocess
edited Aug 31 '17 at 8:51
jfs
269k815721120
269k815721120
asked Aug 10 '11 at 5:21
SynapseSynapse
59641019
59641019
Try usingspawn
family instead.
– Keith
Aug 10 '11 at 5:23
related: Running a process in pythonw with Popen without a console
– jfs
May 22 '14 at 0:47
add a comment |
Try usingspawn
family instead.
– Keith
Aug 10 '11 at 5:23
related: Running a process in pythonw with Popen without a console
– jfs
May 22 '14 at 0:47
Try using
spawn
family instead.– Keith
Aug 10 '11 at 5:23
Try using
spawn
family instead.– Keith
Aug 10 '11 at 5:23
related: Running a process in pythonw with Popen without a console
– jfs
May 22 '14 at 0:47
related: Running a process in pythonw with Popen without a console
– jfs
May 22 '14 at 0:47
add a comment |
4 Answers
4
active
oldest
votes
The process STARTUPINFO
can hide the console window:
si = subprocess.STARTUPINFO()
si.dwFlags |= subprocess.STARTF_USESHOWWINDOW
#si.wShowWindow = subprocess.SW_HIDE # default
subprocess.call('taskkill /F /IM exename.exe', startupinfo=si)
Or set the creation flags to disable creating the window:
CREATE_NO_WINDOW = 0x08000000
subprocess.call('taskkill /F /IM exename.exe', creationflags=CREATE_NO_WINDOW)
The above is still a console process with valid handles for console I/O (verified by calling GetFileType
on the handles returned by GetStdHandle
). It just has no window and doesn't inherit the parent's console, if any.
You can go a step farther by forcing the child to have no console at all:
DETACHED_PROCESS = 0x00000008
subprocess.call('taskkill /F /IM exename.exe', creationflags=DETACHED_PROCESS)
In this case the child's standard handles (i.e. GetStdHandle
) are 0, but you can set them to an open disk file or pipe such as subprocess.DEVNULL
(3.3) or subprocess.PIPE
.
Thank you, it works.
– Synapse
Aug 10 '11 at 6:10
creationflags=CREATE_NO_WINDOW
does no seem to be very portable
– Cyan
May 23 '16 at 12:52
1
@Cyan, in what sense isCREATE_NO_WINDOW
not portable? This is a Windows question, and these flags should be supported in all versions of Windows NT, from 3.1 to Windows 10.
– eryksun
May 23 '16 at 19:59
Python 3.7 now has subprocess.CREATE_NO_WINDOW
– Harmon758
Feb 24 at 7:54
@Harmon758, I'm aware. The priority-class creation flags were being added, and I suggested that we may as well add some of the others, including the console flagsCREATE_NO_WINDOW
andDETACHED_PROCESS
and two others that are unrelated to the console --CREATE_BREAKAWAY_FROM_JOB
andCREATE_DEFAULT_ERROR_MODE
.
– eryksun
Feb 24 at 8:09
|
show 2 more comments
Add the shell=True
argument to the subprocess calls.
subprocess.call('taskkill /F /IM exename.exe', shell=True)
Or, if you don't need to wait for it, use subprocess.Popen
rather than subprocess.call
.
subprocess.Popen('taskkill /F /IM exename.exe', shell=True)
Sure, the startupinfo technique works, but this one's shorter (but put a comment in to indicate why you're usingshell=True
otherwise it probably wouldn't be as obvious).
– Chris Morgan
Sep 22 '11 at 2:56
Hmm, for some reason my executable not running when usingshell=True
. But it run just fine when using startupinfo.
– arifwn
Sep 20 '12 at 21:05
@arifwn: post a new question, please.
– Chris Morgan
Sep 21 '12 at 7:32
3
+1 for brevity. This way has subprocess configureSTARTUPINFO
for you. Note that running viacmd /c
should only be used with trusted commands. In this case it's OK.
– eryksun
Jul 24 '13 at 15:48
6
Not a good solution. shell=True does more than you want, and opens up security problems if the user can manipulate the input.
– jmnben
Aug 11 '15 at 7:41
|
show 5 more comments
Try subprocess.Popen(["function","option1","option2"],shell=False)
.
sorry, the stuff I want to invoke cannot be run by subprocess.Popen, coz exception raised "invalid win32 app". But os.system can run it without any warning.
– Synapse
Aug 10 '11 at 6:11
Er, that's not a problem with subprocess; I can run it on Windows 7, natively (Python 2.7.2) as well as under Cygwin (Python 2.6.5), with no warnings.
– ambagesia
Aug 11 '11 at 23:35
1
Doesn't work for me, the console still pops up. Also theshell
argument defaults toFalse
. Explicitly passing it should not make a difference.
– AXO
Dec 9 '15 at 11:53
add a comment |
try to change the extension from .py to .pyw
3
Hi, please provide some additional narrative to explain how this answers the question. Thanks.
– MandyShaw
Nov 3 '18 at 19:31
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f7006238%2fhow-do-i-hide-the-console-when-i-use-os-system-or-subprocess-call%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
4 Answers
4
active
oldest
votes
4 Answers
4
active
oldest
votes
active
oldest
votes
active
oldest
votes
The process STARTUPINFO
can hide the console window:
si = subprocess.STARTUPINFO()
si.dwFlags |= subprocess.STARTF_USESHOWWINDOW
#si.wShowWindow = subprocess.SW_HIDE # default
subprocess.call('taskkill /F /IM exename.exe', startupinfo=si)
Or set the creation flags to disable creating the window:
CREATE_NO_WINDOW = 0x08000000
subprocess.call('taskkill /F /IM exename.exe', creationflags=CREATE_NO_WINDOW)
The above is still a console process with valid handles for console I/O (verified by calling GetFileType
on the handles returned by GetStdHandle
). It just has no window and doesn't inherit the parent's console, if any.
You can go a step farther by forcing the child to have no console at all:
DETACHED_PROCESS = 0x00000008
subprocess.call('taskkill /F /IM exename.exe', creationflags=DETACHED_PROCESS)
In this case the child's standard handles (i.e. GetStdHandle
) are 0, but you can set them to an open disk file or pipe such as subprocess.DEVNULL
(3.3) or subprocess.PIPE
.
Thank you, it works.
– Synapse
Aug 10 '11 at 6:10
creationflags=CREATE_NO_WINDOW
does no seem to be very portable
– Cyan
May 23 '16 at 12:52
1
@Cyan, in what sense isCREATE_NO_WINDOW
not portable? This is a Windows question, and these flags should be supported in all versions of Windows NT, from 3.1 to Windows 10.
– eryksun
May 23 '16 at 19:59
Python 3.7 now has subprocess.CREATE_NO_WINDOW
– Harmon758
Feb 24 at 7:54
@Harmon758, I'm aware. The priority-class creation flags were being added, and I suggested that we may as well add some of the others, including the console flagsCREATE_NO_WINDOW
andDETACHED_PROCESS
and two others that are unrelated to the console --CREATE_BREAKAWAY_FROM_JOB
andCREATE_DEFAULT_ERROR_MODE
.
– eryksun
Feb 24 at 8:09
|
show 2 more comments
The process STARTUPINFO
can hide the console window:
si = subprocess.STARTUPINFO()
si.dwFlags |= subprocess.STARTF_USESHOWWINDOW
#si.wShowWindow = subprocess.SW_HIDE # default
subprocess.call('taskkill /F /IM exename.exe', startupinfo=si)
Or set the creation flags to disable creating the window:
CREATE_NO_WINDOW = 0x08000000
subprocess.call('taskkill /F /IM exename.exe', creationflags=CREATE_NO_WINDOW)
The above is still a console process with valid handles for console I/O (verified by calling GetFileType
on the handles returned by GetStdHandle
). It just has no window and doesn't inherit the parent's console, if any.
You can go a step farther by forcing the child to have no console at all:
DETACHED_PROCESS = 0x00000008
subprocess.call('taskkill /F /IM exename.exe', creationflags=DETACHED_PROCESS)
In this case the child's standard handles (i.e. GetStdHandle
) are 0, but you can set them to an open disk file or pipe such as subprocess.DEVNULL
(3.3) or subprocess.PIPE
.
Thank you, it works.
– Synapse
Aug 10 '11 at 6:10
creationflags=CREATE_NO_WINDOW
does no seem to be very portable
– Cyan
May 23 '16 at 12:52
1
@Cyan, in what sense isCREATE_NO_WINDOW
not portable? This is a Windows question, and these flags should be supported in all versions of Windows NT, from 3.1 to Windows 10.
– eryksun
May 23 '16 at 19:59
Python 3.7 now has subprocess.CREATE_NO_WINDOW
– Harmon758
Feb 24 at 7:54
@Harmon758, I'm aware. The priority-class creation flags were being added, and I suggested that we may as well add some of the others, including the console flagsCREATE_NO_WINDOW
andDETACHED_PROCESS
and two others that are unrelated to the console --CREATE_BREAKAWAY_FROM_JOB
andCREATE_DEFAULT_ERROR_MODE
.
– eryksun
Feb 24 at 8:09
|
show 2 more comments
The process STARTUPINFO
can hide the console window:
si = subprocess.STARTUPINFO()
si.dwFlags |= subprocess.STARTF_USESHOWWINDOW
#si.wShowWindow = subprocess.SW_HIDE # default
subprocess.call('taskkill /F /IM exename.exe', startupinfo=si)
Or set the creation flags to disable creating the window:
CREATE_NO_WINDOW = 0x08000000
subprocess.call('taskkill /F /IM exename.exe', creationflags=CREATE_NO_WINDOW)
The above is still a console process with valid handles for console I/O (verified by calling GetFileType
on the handles returned by GetStdHandle
). It just has no window and doesn't inherit the parent's console, if any.
You can go a step farther by forcing the child to have no console at all:
DETACHED_PROCESS = 0x00000008
subprocess.call('taskkill /F /IM exename.exe', creationflags=DETACHED_PROCESS)
In this case the child's standard handles (i.e. GetStdHandle
) are 0, but you can set them to an open disk file or pipe such as subprocess.DEVNULL
(3.3) or subprocess.PIPE
.
The process STARTUPINFO
can hide the console window:
si = subprocess.STARTUPINFO()
si.dwFlags |= subprocess.STARTF_USESHOWWINDOW
#si.wShowWindow = subprocess.SW_HIDE # default
subprocess.call('taskkill /F /IM exename.exe', startupinfo=si)
Or set the creation flags to disable creating the window:
CREATE_NO_WINDOW = 0x08000000
subprocess.call('taskkill /F /IM exename.exe', creationflags=CREATE_NO_WINDOW)
The above is still a console process with valid handles for console I/O (verified by calling GetFileType
on the handles returned by GetStdHandle
). It just has no window and doesn't inherit the parent's console, if any.
You can go a step farther by forcing the child to have no console at all:
DETACHED_PROCESS = 0x00000008
subprocess.call('taskkill /F /IM exename.exe', creationflags=DETACHED_PROCESS)
In this case the child's standard handles (i.e. GetStdHandle
) are 0, but you can set them to an open disk file or pipe such as subprocess.DEVNULL
(3.3) or subprocess.PIPE
.
edited Sep 9 '14 at 22:55
answered Aug 10 '11 at 5:48
eryksuneryksun
23.7k25268
23.7k25268
Thank you, it works.
– Synapse
Aug 10 '11 at 6:10
creationflags=CREATE_NO_WINDOW
does no seem to be very portable
– Cyan
May 23 '16 at 12:52
1
@Cyan, in what sense isCREATE_NO_WINDOW
not portable? This is a Windows question, and these flags should be supported in all versions of Windows NT, from 3.1 to Windows 10.
– eryksun
May 23 '16 at 19:59
Python 3.7 now has subprocess.CREATE_NO_WINDOW
– Harmon758
Feb 24 at 7:54
@Harmon758, I'm aware. The priority-class creation flags were being added, and I suggested that we may as well add some of the others, including the console flagsCREATE_NO_WINDOW
andDETACHED_PROCESS
and two others that are unrelated to the console --CREATE_BREAKAWAY_FROM_JOB
andCREATE_DEFAULT_ERROR_MODE
.
– eryksun
Feb 24 at 8:09
|
show 2 more comments
Thank you, it works.
– Synapse
Aug 10 '11 at 6:10
creationflags=CREATE_NO_WINDOW
does no seem to be very portable
– Cyan
May 23 '16 at 12:52
1
@Cyan, in what sense isCREATE_NO_WINDOW
not portable? This is a Windows question, and these flags should be supported in all versions of Windows NT, from 3.1 to Windows 10.
– eryksun
May 23 '16 at 19:59
Python 3.7 now has subprocess.CREATE_NO_WINDOW
– Harmon758
Feb 24 at 7:54
@Harmon758, I'm aware. The priority-class creation flags were being added, and I suggested that we may as well add some of the others, including the console flagsCREATE_NO_WINDOW
andDETACHED_PROCESS
and two others that are unrelated to the console --CREATE_BREAKAWAY_FROM_JOB
andCREATE_DEFAULT_ERROR_MODE
.
– eryksun
Feb 24 at 8:09
Thank you, it works.
– Synapse
Aug 10 '11 at 6:10
Thank you, it works.
– Synapse
Aug 10 '11 at 6:10
creationflags=CREATE_NO_WINDOW
does no seem to be very portable– Cyan
May 23 '16 at 12:52
creationflags=CREATE_NO_WINDOW
does no seem to be very portable– Cyan
May 23 '16 at 12:52
1
1
@Cyan, in what sense is
CREATE_NO_WINDOW
not portable? This is a Windows question, and these flags should be supported in all versions of Windows NT, from 3.1 to Windows 10.– eryksun
May 23 '16 at 19:59
@Cyan, in what sense is
CREATE_NO_WINDOW
not portable? This is a Windows question, and these flags should be supported in all versions of Windows NT, from 3.1 to Windows 10.– eryksun
May 23 '16 at 19:59
Python 3.7 now has subprocess.CREATE_NO_WINDOW
– Harmon758
Feb 24 at 7:54
Python 3.7 now has subprocess.CREATE_NO_WINDOW
– Harmon758
Feb 24 at 7:54
@Harmon758, I'm aware. The priority-class creation flags were being added, and I suggested that we may as well add some of the others, including the console flags
CREATE_NO_WINDOW
and DETACHED_PROCESS
and two others that are unrelated to the console -- CREATE_BREAKAWAY_FROM_JOB
and CREATE_DEFAULT_ERROR_MODE
.– eryksun
Feb 24 at 8:09
@Harmon758, I'm aware. The priority-class creation flags were being added, and I suggested that we may as well add some of the others, including the console flags
CREATE_NO_WINDOW
and DETACHED_PROCESS
and two others that are unrelated to the console -- CREATE_BREAKAWAY_FROM_JOB
and CREATE_DEFAULT_ERROR_MODE
.– eryksun
Feb 24 at 8:09
|
show 2 more comments
Add the shell=True
argument to the subprocess calls.
subprocess.call('taskkill /F /IM exename.exe', shell=True)
Or, if you don't need to wait for it, use subprocess.Popen
rather than subprocess.call
.
subprocess.Popen('taskkill /F /IM exename.exe', shell=True)
Sure, the startupinfo technique works, but this one's shorter (but put a comment in to indicate why you're usingshell=True
otherwise it probably wouldn't be as obvious).
– Chris Morgan
Sep 22 '11 at 2:56
Hmm, for some reason my executable not running when usingshell=True
. But it run just fine when using startupinfo.
– arifwn
Sep 20 '12 at 21:05
@arifwn: post a new question, please.
– Chris Morgan
Sep 21 '12 at 7:32
3
+1 for brevity. This way has subprocess configureSTARTUPINFO
for you. Note that running viacmd /c
should only be used with trusted commands. In this case it's OK.
– eryksun
Jul 24 '13 at 15:48
6
Not a good solution. shell=True does more than you want, and opens up security problems if the user can manipulate the input.
– jmnben
Aug 11 '15 at 7:41
|
show 5 more comments
Add the shell=True
argument to the subprocess calls.
subprocess.call('taskkill /F /IM exename.exe', shell=True)
Or, if you don't need to wait for it, use subprocess.Popen
rather than subprocess.call
.
subprocess.Popen('taskkill /F /IM exename.exe', shell=True)
Sure, the startupinfo technique works, but this one's shorter (but put a comment in to indicate why you're usingshell=True
otherwise it probably wouldn't be as obvious).
– Chris Morgan
Sep 22 '11 at 2:56
Hmm, for some reason my executable not running when usingshell=True
. But it run just fine when using startupinfo.
– arifwn
Sep 20 '12 at 21:05
@arifwn: post a new question, please.
– Chris Morgan
Sep 21 '12 at 7:32
3
+1 for brevity. This way has subprocess configureSTARTUPINFO
for you. Note that running viacmd /c
should only be used with trusted commands. In this case it's OK.
– eryksun
Jul 24 '13 at 15:48
6
Not a good solution. shell=True does more than you want, and opens up security problems if the user can manipulate the input.
– jmnben
Aug 11 '15 at 7:41
|
show 5 more comments
Add the shell=True
argument to the subprocess calls.
subprocess.call('taskkill /F /IM exename.exe', shell=True)
Or, if you don't need to wait for it, use subprocess.Popen
rather than subprocess.call
.
subprocess.Popen('taskkill /F /IM exename.exe', shell=True)
Add the shell=True
argument to the subprocess calls.
subprocess.call('taskkill /F /IM exename.exe', shell=True)
Or, if you don't need to wait for it, use subprocess.Popen
rather than subprocess.call
.
subprocess.Popen('taskkill /F /IM exename.exe', shell=True)
answered Sep 22 '11 at 2:55
Chris MorganChris Morgan
58.3k13143175
58.3k13143175
Sure, the startupinfo technique works, but this one's shorter (but put a comment in to indicate why you're usingshell=True
otherwise it probably wouldn't be as obvious).
– Chris Morgan
Sep 22 '11 at 2:56
Hmm, for some reason my executable not running when usingshell=True
. But it run just fine when using startupinfo.
– arifwn
Sep 20 '12 at 21:05
@arifwn: post a new question, please.
– Chris Morgan
Sep 21 '12 at 7:32
3
+1 for brevity. This way has subprocess configureSTARTUPINFO
for you. Note that running viacmd /c
should only be used with trusted commands. In this case it's OK.
– eryksun
Jul 24 '13 at 15:48
6
Not a good solution. shell=True does more than you want, and opens up security problems if the user can manipulate the input.
– jmnben
Aug 11 '15 at 7:41
|
show 5 more comments
Sure, the startupinfo technique works, but this one's shorter (but put a comment in to indicate why you're usingshell=True
otherwise it probably wouldn't be as obvious).
– Chris Morgan
Sep 22 '11 at 2:56
Hmm, for some reason my executable not running when usingshell=True
. But it run just fine when using startupinfo.
– arifwn
Sep 20 '12 at 21:05
@arifwn: post a new question, please.
– Chris Morgan
Sep 21 '12 at 7:32
3
+1 for brevity. This way has subprocess configureSTARTUPINFO
for you. Note that running viacmd /c
should only be used with trusted commands. In this case it's OK.
– eryksun
Jul 24 '13 at 15:48
6
Not a good solution. shell=True does more than you want, and opens up security problems if the user can manipulate the input.
– jmnben
Aug 11 '15 at 7:41
Sure, the startupinfo technique works, but this one's shorter (but put a comment in to indicate why you're using
shell=True
otherwise it probably wouldn't be as obvious).– Chris Morgan
Sep 22 '11 at 2:56
Sure, the startupinfo technique works, but this one's shorter (but put a comment in to indicate why you're using
shell=True
otherwise it probably wouldn't be as obvious).– Chris Morgan
Sep 22 '11 at 2:56
Hmm, for some reason my executable not running when using
shell=True
. But it run just fine when using startupinfo.– arifwn
Sep 20 '12 at 21:05
Hmm, for some reason my executable not running when using
shell=True
. But it run just fine when using startupinfo.– arifwn
Sep 20 '12 at 21:05
@arifwn: post a new question, please.
– Chris Morgan
Sep 21 '12 at 7:32
@arifwn: post a new question, please.
– Chris Morgan
Sep 21 '12 at 7:32
3
3
+1 for brevity. This way has subprocess configure
STARTUPINFO
for you. Note that running via cmd /c
should only be used with trusted commands. In this case it's OK.– eryksun
Jul 24 '13 at 15:48
+1 for brevity. This way has subprocess configure
STARTUPINFO
for you. Note that running via cmd /c
should only be used with trusted commands. In this case it's OK.– eryksun
Jul 24 '13 at 15:48
6
6
Not a good solution. shell=True does more than you want, and opens up security problems if the user can manipulate the input.
– jmnben
Aug 11 '15 at 7:41
Not a good solution. shell=True does more than you want, and opens up security problems if the user can manipulate the input.
– jmnben
Aug 11 '15 at 7:41
|
show 5 more comments
Try subprocess.Popen(["function","option1","option2"],shell=False)
.
sorry, the stuff I want to invoke cannot be run by subprocess.Popen, coz exception raised "invalid win32 app". But os.system can run it without any warning.
– Synapse
Aug 10 '11 at 6:11
Er, that's not a problem with subprocess; I can run it on Windows 7, natively (Python 2.7.2) as well as under Cygwin (Python 2.6.5), with no warnings.
– ambagesia
Aug 11 '11 at 23:35
1
Doesn't work for me, the console still pops up. Also theshell
argument defaults toFalse
. Explicitly passing it should not make a difference.
– AXO
Dec 9 '15 at 11:53
add a comment |
Try subprocess.Popen(["function","option1","option2"],shell=False)
.
sorry, the stuff I want to invoke cannot be run by subprocess.Popen, coz exception raised "invalid win32 app". But os.system can run it without any warning.
– Synapse
Aug 10 '11 at 6:11
Er, that's not a problem with subprocess; I can run it on Windows 7, natively (Python 2.7.2) as well as under Cygwin (Python 2.6.5), with no warnings.
– ambagesia
Aug 11 '11 at 23:35
1
Doesn't work for me, the console still pops up. Also theshell
argument defaults toFalse
. Explicitly passing it should not make a difference.
– AXO
Dec 9 '15 at 11:53
add a comment |
Try subprocess.Popen(["function","option1","option2"],shell=False)
.
Try subprocess.Popen(["function","option1","option2"],shell=False)
.
answered Aug 10 '11 at 5:30
ambagesiaambagesia
363111
363111
sorry, the stuff I want to invoke cannot be run by subprocess.Popen, coz exception raised "invalid win32 app". But os.system can run it without any warning.
– Synapse
Aug 10 '11 at 6:11
Er, that's not a problem with subprocess; I can run it on Windows 7, natively (Python 2.7.2) as well as under Cygwin (Python 2.6.5), with no warnings.
– ambagesia
Aug 11 '11 at 23:35
1
Doesn't work for me, the console still pops up. Also theshell
argument defaults toFalse
. Explicitly passing it should not make a difference.
– AXO
Dec 9 '15 at 11:53
add a comment |
sorry, the stuff I want to invoke cannot be run by subprocess.Popen, coz exception raised "invalid win32 app". But os.system can run it without any warning.
– Synapse
Aug 10 '11 at 6:11
Er, that's not a problem with subprocess; I can run it on Windows 7, natively (Python 2.7.2) as well as under Cygwin (Python 2.6.5), with no warnings.
– ambagesia
Aug 11 '11 at 23:35
1
Doesn't work for me, the console still pops up. Also theshell
argument defaults toFalse
. Explicitly passing it should not make a difference.
– AXO
Dec 9 '15 at 11:53
sorry, the stuff I want to invoke cannot be run by subprocess.Popen, coz exception raised "invalid win32 app". But os.system can run it without any warning.
– Synapse
Aug 10 '11 at 6:11
sorry, the stuff I want to invoke cannot be run by subprocess.Popen, coz exception raised "invalid win32 app". But os.system can run it without any warning.
– Synapse
Aug 10 '11 at 6:11
Er, that's not a problem with subprocess; I can run it on Windows 7, natively (Python 2.7.2) as well as under Cygwin (Python 2.6.5), with no warnings.
– ambagesia
Aug 11 '11 at 23:35
Er, that's not a problem with subprocess; I can run it on Windows 7, natively (Python 2.7.2) as well as under Cygwin (Python 2.6.5), with no warnings.
– ambagesia
Aug 11 '11 at 23:35
1
1
Doesn't work for me, the console still pops up. Also the
shell
argument defaults to False
. Explicitly passing it should not make a difference.– AXO
Dec 9 '15 at 11:53
Doesn't work for me, the console still pops up. Also the
shell
argument defaults to False
. Explicitly passing it should not make a difference.– AXO
Dec 9 '15 at 11:53
add a comment |
try to change the extension from .py to .pyw
3
Hi, please provide some additional narrative to explain how this answers the question. Thanks.
– MandyShaw
Nov 3 '18 at 19:31
add a comment |
try to change the extension from .py to .pyw
3
Hi, please provide some additional narrative to explain how this answers the question. Thanks.
– MandyShaw
Nov 3 '18 at 19:31
add a comment |
try to change the extension from .py to .pyw
try to change the extension from .py to .pyw
answered Nov 3 '18 at 19:10
neferjinaneferjina
72
72
3
Hi, please provide some additional narrative to explain how this answers the question. Thanks.
– MandyShaw
Nov 3 '18 at 19:31
add a comment |
3
Hi, please provide some additional narrative to explain how this answers the question. Thanks.
– MandyShaw
Nov 3 '18 at 19:31
3
3
Hi, please provide some additional narrative to explain how this answers the question. Thanks.
– MandyShaw
Nov 3 '18 at 19:31
Hi, please provide some additional narrative to explain how this answers the question. Thanks.
– MandyShaw
Nov 3 '18 at 19:31
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f7006238%2fhow-do-i-hide-the-console-when-i-use-os-system-or-subprocess-call%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Try using
spawn
family instead.– Keith
Aug 10 '11 at 5:23
related: Running a process in pythonw with Popen without a console
– jfs
May 22 '14 at 0:47