Category : subprocess

working in python and trying to make a subprocess work in a different directory from parent. made a super simplified test version and its not working def test: testPath1 = ‘C:"%HOMEPATH%"Desktop’ testPath2 = ‘C:UsersuserDesktop’ subprocess.Popen(‘dir’, cwd=testPath1, shell=True) test() this code works for testPath2 but not for testPath1 error: NotADirectoryError: [WinError 267] The directory name is ..

Read more

I have been researching over on how to provide Python subprocess it’s own time and memory. import resource import subprocess def set_memory_time(seconds): limit_virtual_memory(seconds) usage_start = resource.getrusage(resource.RUSAGE_CHILDREN) print("usage_start ", usage_start) try: p = subprocess.check_output( [‘docker exec -it cpp_compiler sh -c "g++ -o Test1 prog1.cpp && ./Test1 < input.txt"’], shell=True) except Exception as e: print(e) usage_end = ..

Read more

Running on Windows (Admin rights), trying to call other executable from Python via subprocess library: >>> import subprocess >>> subprocess.run([‘C:UsersUserDownloadshashcat-6.2.1hashcat.exe’, ‘–help’], shell=True) hashcat (v6.2.1) starting… CompletedProcess(args=[‘C:UsersUserDownloadshashcat-6.2.1hashcat.exe’, ‘–help’], returncode=4294967295) >>> subprocess.call([‘C:UsersUserDownloadshashcat-6.2.1hashcat.exe’, ‘–help’], shell=True) hashcat (v6.2.1) starting… ./OpenCL/: No such file or directory 4294967295 >>> subprocess.getoutput([‘C:UsersUserDownloadshashcat-6.2.1hashcat.exe’, ‘–help’]) ‘hashcat (v6.2.1) starting…nn./OpenCL/: No such file or directoryn’ As shown, ..

Read more

I am attempting to make this subprocess handler below close the queuehandler background thread cleanly on windows. This example is setup to fail and generates a "Exception ignored" Invalid handle error because the subprocess is terminated. Note: this code only works on Windows cmd.exe if your prompt matches the regex pattern C:.*>$: import sys import ..

Read more

I have a use-case wherein I have used subprocess to pass , DB name and password with sqlcmd. But its not pasrsing the password. Seems like due to special characters. Code Sample: import subprocess file = "1.sql" passwrd = r"hello&2J$9T#3111" s = subprocess.call(["sqlcmd","-t","30", "-S", "HelloServer", "-U", "user1", "-P",passwrd, "-i", "1.sql", "-d","Tst"], shell=True) print(s) Error that ..

Read more

I’m trying to use CMD command with python script for my small "autoinstall" project. Command I want to use: WMIC /NODE:’kv-c112-11′ OS get Caption What I’ve got: result = subprocess.check_output([‘WMIC’, ‘/NODE:"kv-c112-11"’, ‘OS’, ‘get’, ‘Caption’]) result = str(result) print(result) In stdout I see: b” I expect to see: b’Caption rrnx8cxa0xa9xaaxe0xaexe1xaexe4xe2 Windows 10 x8axaexe0xafxaexe0xa0xe2xa8xa2xadxa0xef LTSC rrnrrn’ If ..

Read more

i write a code that works fine. So i created an exe file with pyinstaller. here comes the problem import subprocess import requests requests.get(‘url..’) print(‘something’) subprocess.Popen(‘python script.py’) This last line Popen causing problem. So i made my exe and it working on those computers who have python installed and configured at path. But if i ..

Read more