Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Invalid handle using sys.subprocess #592

Open
aparks123 opened this issue Sep 6, 2019 · 3 comments
Open

Invalid handle using sys.subprocess #592

aparks123 opened this issue Sep 6, 2019 · 3 comments

Comments

@aparks123
Copy link

I have latest preview of RStudio 1.2.1578 and in an RMarkdown document I am running python subprocess (gradle.bat is in path). This command works in python cmd env but not in rstudio.

import sys,subprocess
print("Python Version:")
print(sys.version)
print("Gradle Version:")
sp = subprocess.run(['gradle.bat','-v'],universal_newlines=True,stdout=subprocess.PIPE)

get an invalid handle error:

Python Version:
3.7.4 (tags/v3.7.4:e09359112e, Jul 8 2019, 20:34:20) [MSC v.1916 64 bit (AMD64)]
Gradle Version:
OSError: [WinError 6] The handle is invalid

Detailed traceback:
File "", line 1, in
File "C:\PYTHON2\lib\subprocess.py", line 472, in run
with Popen(*popenargs, **kwargs) as process:
File "C:\PYTHON
2\lib\subprocess.py", line 728, in init
errread, errwrite) = self._get_handles(stdin, stdout, stderr)
File "C:\PYTHON~2\lib\subprocess.py", line 1025, in _get_handles
p2cread = _winapi.GetStdHandle(_winapi.STD_INPUT_HANDLE)

@kevinushey
Copy link
Collaborator

Perhaps related to: #518

I wonder if you can run the subprocesses with stdin read explicitly from an empty file or something similar.

@aparks123
Copy link
Author

aparks123 commented Sep 12, 2019

I could probably pipe output to an actual temp file somewhere and read that. Kind of hacky though.

--UPDATE
That actually doesn't work either, same invalid handle error:

f=open("temp.out","w+")
print("Gradle Version:")
sp = subprocess.run(['gradle.bat','-v'],universal_newlines=True,stdout=f,shell=True)

@cajasc
Copy link

cajasc commented Jul 13, 2021

@aparks123

I´m getting the same error when running

import subprocess

subprocess.run(" ".join([r'"C:/Program Files (x86)/Renewable NRG Systems/SymPRO Desktop/SymPRODesktop.exe"']), stdout=subprocess.PIPE)

Did you solve it?

some help?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants