Advertisement
surik00

Py Subprocess

Jun 28th, 2018
123
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.51 KB | None | 0 0
  1. import subprocess
  2.  
  3.  
  4. PS_PATH = 'C:\\WINDOWS\\system32\\WindowsPowerShell\\v1.0\\powershell.exe'
  5. # PS_PATH = 'C:\\Windows\\System32\\WindowsPowerShell\\v1.0\\powershell.exe -version 2.0 -noexit'
  6.  
  7. script = '''
  8. Write-Host "hello, world!"
  9. '''.encode('cp866')
  10.  
  11.  
  12. def ps_comm():
  13.     proc = subprocess.Popen(
  14.         [PS_PATH],
  15.         stdin=subprocess.PIPE,
  16.         stdout=subprocess.PIPE
  17.     )
  18.     out, err = proc.communicate(script)
  19.     print(out)
  20.  
  21.  
  22. print('starting')
  23. print(ps_comm())
  24. print('exiting')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement