I have board server, in which i want to execute a gstreamer command from parmiko which will take the input file as a argument
this one is working
stdin,stdout,stderr=ssh_client.exec_command('ls')
want to execute below command but not working
stdin,stdout,stderr=ssh_client.exec_command('gst_app /media/card/pipeline.cfg')
want to execute a gst_app /media/card/pipeline.cfg command from ssh_client.exec_command
can anyone please help
If a command does not work, start by reading its error output.
Use stderr.readlines() for that.
Quite often the error is "<command> not found". For that see
Some Unix commands fail with "<command> not found", when executed using Python Paramiko exec_command
Related
When I execute "Get-WindowsOptionalFeature -Online" command in Windows2016 server powershell, the output is all fine, but when I execute with the Python script below,
cmd = os.popen("Get-WindowsOptionalFeature -Online")
print(cmd.read())
the output is empty.
is there something wrong with my code?
I tried to exec ipconfig using this code, it worked fine
My error comes from my ignorance of powershell. I regard powershell as cmd, so I directly use os.popen to call the command to be executed. In fact, you need to call powershell first to execute the command that needs to be executed, the following is an example:
import subprocess;
process=subprocess.Popen(["powershell","Get-WindowsOptionalFeature -Online"],stdout=subprocess.PIPE);
result=process.communicate()[0]
I am trying to run a simple python script from my command line. It works fine when I run the python script on its own but when I call it from the command line nothing happens. I don't even get an error. Python is added to my path. This is what I'm doing.
cmd C:\users\RGilsburg\Desktop\a\untitled1.py
The command prompt just proceeds to print the Microsoft Version and copyright details.
Anyone know what is causing this?
To run the script
python C:\users\RGilsburg\Desktop\a\untitled1.py
I am getting this error on running a subprocess.check_call that runs an ogr2ogr command.
I have put on error trapping but can't see the error details and the cmd window closes without me being able to see the problem.
How can I trace the problem?
The screen grab shows the working code (when typed in), the python script and the output of python shell.
One issue maybe the ' in the python generated code. The command is built based on https://gis.stackexchange.com/questions/154004/execute-ogr2ogr-from-python/246667 where each option is wrapped in "[OPTION]",
Figured it out with a colleague...
Needed to
Load this in a batch shell that had the paths to ogr
Trust that subprocess takes care of the extra "EPSG:23555" when required and not do "\"EPS...\"" to get the code to be the same as what runs in OSGEO4W Shell.
Running the .py file from powershell rather than IDLE/Pyscripter
I want to execute some adb commands from python script. But when i executed the following line
os.system('adb devices')
The cmd returns with 1 instead of 0. I also tried executing
os.popen('adb devices').read()
I am getting empty string. Please help me to solve this.
Note: I tried the same commands from command window and it was working fine. I also added the path of adb.exe to windows PATH environment variable.
According to Windows docs, you've got 1, because there was an error on your command.
Maybe use subprocess could be a better approach.
import subprocess
subprocess.check_output(
"adb devices",
stderr=subprocess.STDOUT,
shell=True)
I am using python subprocess module to run some command and store its output in background. The command is deployed on my machine. Now whenever i run the command from shell prompt it works fine. But when I try to run the same command using subprocess module it gives following error
The command to be executed is vxswadm listswitch all
process = subprocess.Popen('vxswadm listswitch all > tmp.txt &',shell=True)
>>> Traceback (most recent call last):
File "/usr/bin/vxswadm", line 30, in <module>
l.uname = os.getlogin()
OSError: [Errno 25] Inappropriate ioctl for device
Can anyone help me out to fix this error . Any suggestions will be helpful. Thanks in advance
Tazim
The problem is likely due to the bash shell terminating immediately after the & and sending the SIGHUP singal to all of it's subprocesses (standard shell behavior).
You can use the subprocess module to directly execute the command and can redirect the output to tmp.txt yourself by first opening the file and then by passing it's file handle to the stdout argument of the Popen call.
There is a problem with os.getlogin() and subprocessing and python.
See http://code.activestate.com/lists/python-list/288845/
You need to use something else, such as:
pwd.getpwuid(os.getuid()).pw_name (Unix only)
See also the discussion on a portable way to get the username.
Try changing it to ['vxswadm', 'listswitch', 'all', '>', 'tmp.txt','&'] and/or changing shell to False.
I think it might be the shell bit, though (if that fixes it).
You may also try adding stdin=subprocess.PIPE, stdout=subprocess.PIPE, though I doubt that will affect it.