mardi 23 avril 2019

Execution of bat file using pypsexc module result in hang

I am automating test cases for some xyz.bat file. To run it remotely on windows I am trying to use pypsexc module. I followed setup steps and sample code from https://pypi.org/project/pypsexec/ and it works fine but when I tried to run xyz.bat file which is in C:\myfolder\myfolder2\ python execution result in infinite hang.

Here is my code

from pypsexec.client import Client 
c = Client("<machine IP>", username="Admin", password="passowrd") 

c.connect()                                                                    
try:                                                                           
    c.create_service()  
    stdout, stderr, rc = c.run_executable("cmd.exe",                       arguments="/c echo Hello World")        
    print stdout,stderr                                                                                                                              
    cmd = "xyz.bat -h"
    stdout, stderr, rc = c.run_executable(                                     
        "cmd", use_system_account=True,working_dir="C:\myfolder \myfolder2")             
    print stdout,stderr  
finally:                                                                       
    c.remove_service()                   
    c.disconnect()

can you please tell what am I doing wrong here ?? also please suggest if there is any better alternative.

Aucun commentaire:

Enregistrer un commentaire