I initially tried to execute Python code in a different environment using subprocess. In the process, three arguments (1 divisionary, 2 path) were handed over to the subprocess, but only part of the divisionary arrived in the subprocess and two paths did not.
kwargs = {"stdin": subprocess.PIPE, "stdout": subprocess.PIPE, "env": env}
with subprocess.Popen([interpreter, fr'..\another_project\another_file.py'] + arg, **kwargs, bufsize=-1,
shell=True) as proc:
out, err = proc.communicate()
if err is not None:
print(err)
So I modified the code as follows, but this time, the instrument does not arrive at all. I thought there was a problem with the 'bufsize' parameter and corrected the value, but the result was the same.
arg_string = json.dumps(arg[0]).encode('utf-8')
arg_string += b"!" + bytes(arg[1], encoding='utf-8')
arg_string += b"!" + bytes(arg[2], encoding='utf-8')
kwargs = {"stdin": subprocess.PIPE, "stdout": subprocess.PIPE, "env": env}
with subprocess.Popen(fr'{interpreter} ..\another_project\another_file.py', **kwargs, bufsize=-1,
shell=True) as proc:
out, err = proc.communicate(input=arg_string, timeout=None)
if err is not None:
print(err)
What the subprocess does is to take over the dictionary and path and create a json file.
How can I solve this problem?