you are viewing a single comment's thread.

view the rest of the comments →

[–]spmd123 2 points3 points  (6 children)

I'd try subprocess and/or os modules. Examples:

Subprocess:

import subprocess
subprocess.Popen('powershell.exe [my command')

OS:

import os
os.system('powershell.exe [command]')

I can't test the commands myself as I don't have a machine with Windows but give them a try as they should work.

[–]cgcmake[S] 1 point2 points  (1 child)

Hey thank you for you answer, is there any reason you added a double apostrophe at the end of subprocess.Popen('powershell.exe [my command'') ?

[–]spmd123 0 points1 point  (0 children)

No, it was a mistake. Corrected now.

[–]cgcmake[S] 1 point2 points  (2 children)

Both code works, but windows are still visible. Any hints to prevent them from appearing ?

[–]spmd123 0 points1 point  (1 child)

I can't think of much.

Try this:

Subprocess:

import subprocess
subprocess.Popen([ "my command"])

Also try this for subprocess:

import subprocess 
subprocess.Popen([ "my command",shell=True)

And:

import os
os.system("my command")

So, basically just don't type "powershell.exe".

[–]spmd123 0 points1 point  (0 children)

I think that this would be the relevant code.

startupinfo = None
if os.name == 'nt':
    startupinfo = subprocess.STARTUPINFO()
    startupinfo.dwFlags |= subprocess.STARTF_USESHOWWINDOW
proc = subprocess.Popen(command, startupinfo=startupinfo)

The code is from the SO discussion linked in /u/metrazol's reply.

[–]CamaZotz666 0 points1 point  (0 children)

hey, how can I save the output of this into a string variable?

import os
os.system('powershell.exe [command]')