Python Forum
issues while using Psexec from python code
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
issues while using Psexec from python code
#1
Hi All,

I am relatively new to python and this forum as well. I was recently working on a code which requires me to connect to a remote machine via python and execute a certain batch file. Following is the code which when executed doesn't give any error, but doesn't do the expected either. This is being run from jython 2.5.1 which is part of an application suite (hyperion FDMEE).

import com.hyperion.aif.scripting.API as API
import os
import smtplib
import datetime
from email.MIMEMultipart import MIMEMultipart
from email.MIMEText import MIMEText
from subprocess import call
from subprocess import Popen

psbatchpath = "C:\tools\PSTools"
psbatchfile = os.path.join(psbatchpath,'PsExec64.exe')

dbbatchpath = "D:\Test_Batch_Script"
dbbatchfile = os.path.join(dbbatchpath,'test_hello.bat')

hostname = "\\XX.XXX.XXX.XXXX"

try :
	#Popen(['C:\tools\PSTools\PsExec64.exe', '\\XX.XXX.XXX.XXX', '-e' ,'-s' ,'-d' ,'-i' ,'D:\Automation\hello.bat'], shell=True)
	#Popen(['C:\\tools\\PSTools\\PsExec64.exe', '\\\\XX.XXX.XXX.XXX', '-e' ,'-s' ,'-d' ,'-i' ,'D:\\Automation\\hello.bat'], shell=True)
	Popen([psbatchfile, '\\\\XX.XXX.XXX.XXX' , '-i' , dbbatchfile], shell=True)
	#Popen([dbbatchfile], shell=True)
	#call([dbbatchfile], shell=True)
except ImportError, e:
	 fdmAPI.logDebug(" couldnt connect with PsExec")
when I run the same psexec command directly from the command prompt, it runs perfectly fine.
Also, I tried to debug this on my local machine itself, still no avail.
#import com.hyperion.aif.scripting.API as API
import os
import smtplib
import datetime
from email.MIMEMultipart import MIMEMultipart
from email.MIMEText import MIMEText
#from subprocess import call
#from subprocess import Popen
import subprocess

print "this"
print "this"

#cmd = r'c:\PSTools\psexec \\localhost -d cmd /c echo test'
cmd = r'c:\PSTools\psexec \\localhost -d c:\\test_psexc.bat'
myproc = subprocess.Popen(cmd, stdin=None, shell=True, stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
myproc.communicate()

print "this as well"
Request your expert help on this please.

Thanks,
Dev
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
Shocked Issues Installing Pyenv/Python 3.9.1 Brandon_Contactum 1 2,517 Feb-22-2022, 06:32 PM
Last Post: snippsat
  run into issues while configuring visual-studio code on a win 7 machine. apollo 3 3,658 Sep-12-2019, 12:25 AM
Last Post: snippsat
  Code Clean-up and Maya/Python Slicing issues mvvthology 1 2,414 Aug-05-2019, 10:43 PM
Last Post: Yoriz
  TurtleWorld on MAC in Python 3.6 issues benniehanas 3 3,717 Jul-09-2018, 08:00 PM
Last Post: ichabod801
  Issues with Python script as service satishgunjal 8 7,464 Jun-21-2018, 11:40 AM
Last Post: satishgunjal
  python variable issues - using spyder and opencv Afrodizzyjack 5 5,782 Jun-19-2018, 09:46 AM
Last Post: gontajones
  Python random formatting issues Barnettch3 10 5,938 Jan-28-2018, 11:04 PM
Last Post: Gribouillis
  Python and Pika stability issues tremmert 0 45,280 Jun-06-2017, 11:46 AM
Last Post: tremmert
  Issues with running regedit command from python gohanzdad 10 9,899 May-16-2017, 04:28 PM
Last Post: gohanzdad

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020