I am running a jar file from python.
This jar must be run as administrator in order to work.
the python script is run in a jenkins job.
Is there a way to run the jar/python script as and administrator?
either from the jenkins job - or modify the python script.
with subprocess.Popen(command,
cwd=tool_dir,
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
shell=True) as proc:
try:
outs, errs = proc.communicate(timeout=1000)
Thank you!
Related
I have created a Python script and compiled it into an exe file with PyInstaller. In the process, I have specified the -w option to get an app that doesn't have any console.
Everything works fine except the execution of commands using popen:
mout = subprocess.Popen(['ls','C:\'])
This line generates an exception [Error 6] The handle is invalid.
I have tried adding the parameters
stdout=subprocess.PIPE, stderr=subprocess.PIPE but it stills not working. I think that is because the main process doesn't have any console assigned. I want to execute the command but without opening any shell, it has to be transparent to the user.
Is there any option?
This should solve your issue.
proc = subprocess.Popen(['ls','C:\\'], shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE, stdin=subprocess.PIPE, creationflags=CREATE_NO_WINDOW)
In python I know how to launch a command using subprocess.Popen
process = subprocess.Popen(cmd, shell=True, stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
what I have to do is: 1) call an executable .exe command, 2) then after that command is running within it call another command.
So when I do 1) like this:
process = subprocess.Popen("C:\Automation\helpFiles\topCmd.exe", shell=True, stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
once that is running I need to run another command i.e state
how can I do it?
Hi I am trying to create a script using python to log on to a server and to check the status of the cluster by running a clustat command. When I do this I get the following error:
/bin/sh: clustat: command not found
As I understand it, it's not able to run the command as this is a non standard bash command that is being used. I was hoping someone would have some ideas to get around this to get it work.
Below is the method used to run the command:(I have antoher method to ssh onto the system it works fine)
def run_cmd(command):
"""Function for running command on the system."""
proc = subprocess.Popen([command], stdout=subprocess.PIPE, shell=True)
(out, err) = proc.communicate()
return out
This is where it seems to go wrong. I know the run_cmd method works as I am able to use it with other commands:
run_cmd("clustat >> out.txt")
return ""
subprocess runs the commands locally.
You will have to use paramiko.SSHClient to run commands on the remote machine.
ssh_client = paramiko.SSHClient()
ssh_client.connect(host='some_host', username='username', password='password')
ssh_client.exec_command('clustat >> out.txt')
I need to run rsync from Python 2.7 app in windows 7 x64 (using cwRsync 5.5.0).
Everything works fine from command line:
set CWRSYNCHOME in env to cwrsync binaries and run following command
rsync.exe "/cygdrive/e/test" test1#192.168.1.14:
But when trying to run same command as python subprocess:
process = subprocess.Popen(['rsync.exe', '/cygdrive/e/test', 'test1#192.168.1.14:'],
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
shell=True,
env={'CWRSYNCHOME': './bin'})
stdout, stderr = process.communicate()
print 'STDOUT:{}\nSTDERR:{}'.format(stdout, stderr)
I get following error in stderr:
rsync: pipe: Operation not permitted (1)
rsync error: error in IPC code (code 14) at pipe.c(59) [sender=3.1.2]
Here is verbose rsync stdout:
FILE_STRUCT_LEN=16, EXTRA_LEN=4
cmd=<NULL> machine=192.168.1.14 user=test1 path=.
cmd[0]=ssh cmd[1]=-l cmd[2]=test1 cmd[3]=192.168.1.14 cmd[4]=rsync cmd[5]=--server cmd[6]=-vvvvve.LsfxC cmd[7]=. cmd[8]=.
opening connection using: ssh -l test1 192.168.1.14 rsync --server -vvvvve.LsfxC . . (9 args)
[sender] _exit_cleanup(code=14, file=pipe.c, line=59): entered
[sender] _exit_cleanup(code=14, file=pipe.c, line=59): about to call exit(14)
Tryed set shell=False and pass command as single line (not cmd and args) - error stil repeats.
What am i doing wrong ?
To get it work, rsync needs to be runned under cygwin's shell:
process = subprocess.Popen(['sh.exe', '-c',
'rsync /cygdrive/e/test test1#192.168.1.14:'],
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
stdin=subprocess.PIPE,
env={'CWRSYNCHOME': '/bin/',
'PATH': '/bin/'})
It's working (there is no ssh athorization in example above).
I am calling a command executable in Ubuntu using:
proc = subprocess.Popen(commandarray,
stderr=subprocess.STDOUT, stdout=subprocess.PIPE,
bufsize=0, close_fds=ON_POSIX, env=os.environ.copy())
However, when I run this, it is stuck at this step. Is there something I am missing?