0

Im trying to reproduce the following batch file but on command-line oneliner. Id like to be able to use this client in python scripts and to identify if a connection is made I need to be able to retrieve the error codes. I am calling the application via subprocess Any help would be appreciated

BATCH FILE CODE

ECHO OFF START /WAIT rdp.exe /v:192.168.1.122 /u:xpuser /p:xpuser /batch ECHO %ERRORLEVEL% 

I have tried the below commands along with many variations but cant get what is expected. Information on the executable can be found here

EXAMPLE

c:\Python27>start /WAIT rdp.exe /v:192.168.1.122 /u:xpuser /p:xpuser /log /batch | ECHO %ERRORLEVEL% c:\Python27>start rdp.exe /v:192.168.1.122 /u:xpuser /p:xpuser /batch || ECHO %ERRORLEVEL% 

SNIPPET OF PYTHON CODE

 try: cmdrdp = "rdp.exe /v:%s /u:%s /p:%s /log /batch" % (server, username, password) subprocess.check_output(cmdrdp) except CalledProcessError as e: print(e.returncode) else: print "Connected to: %s %s %s" % (server, username, password) 

1 Answer 1

1

If you pass a single string to subprocess.check_output, it's interpeted as the literal file name, if you want it to work you need to pass the shell=True argument.

However, the recommended way of using the subprocess family of functions is with a list of strings as argument:

subprocess.check_output(["rdp.exe", "/v:" + server, "/u:" + username, "/p:" + password, "/log", "/batch"]) 
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.