Python executing Class-dump command - python

I am trying to execute the following code in Python
import os,subprocess
from glob import glob
path = "/Users/armed/private_SDKs"
os.chdir(path)
for file in glob("*.framework"):
command = ['class-dump' , '-H' , file , '-o' , '~', '/Users/armed/Desktop/Headers/']
subprocess.call(command)
On executing this script i get the following error :-
Traceback (most recent call last):
File "<pyshell#52>", line 3, in <module>
subprocess.call(command)
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/subprocess.py", line 493, in call
return Popen(*popenargs, **kwargs).wait()
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/subprocess.py", line 679, in __init__
errread, errwrite)
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/subprocess.py", line 1228, in _execute_child
raise child_exception
OSError: [Errno 13] Permission denied
Any help is much appreciated !

Check permissions of the class-dump command. chmod +x class-dump if it's not executable. Here are the docs on chmod.
You might also need to specify the absolute path to class-dump if it's not on your path.
Also, try:
print " ".join(command)
and see if you can run it by pasting the results into a shell.

Related

Python subprocess using Idle

I am new to python scripting. I am trying to run subprocess methods on Python Idle and getting these errors:
import subprocess
subprocess.check_output("ls")
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "C:\Users\ramakrishna\AppData\Local\Programs\Python\Python36\lib\subprocess.py", line 336, in check_output
**kwargs).stdout
File "C:\Users\ramakrishna\AppData\Local\Programs\Python\Python36\lib\subprocess.py", line 403, in run
with Popen(*popenargs, **kwargs) as process:
File "C:\Users\ramakrishna\AppData\Local\Programs\Python\Python36\lib\subprocess.py", line 707, in __init__
restore_signals, start_new_session)
File "C:\Users\ramakrishna\AppData\Local\Programs\Python\Python36\lib\subprocess.py", line 990, in _execute_child
startupinfo)
FileNotFoundError: [WinError 2] The system cannot find the file specified
Please help me out to resolve this error.
Thank you
seems like you are running windows. Windows has no "ls" command, so you get a FileNotFoundError exception. I am not familiar with windows and python, but try "dir" instead of "ls", that should work.

Getting error with subprocess while running aws s3 cp: [Errno 2] No such file or directory: 'aws'

I am able to execute this command successfully from command line and it copies the desired csv to the s3 bucket aws s3 cp /Users/kaswani/tips.csv s3://dplearn/
But, when I try to run the same from within python using subprocess it throws error:
subprocess.check_output(['aws','s3','cp','/Users/kaswani/tips.csv','s3://dplearn/'])
Error:
Traceback (most recent call last):
File "<input>", line 1, in <module>
File "/Users/kaswani/anaconda/envs/aws/lib/python3.5/subprocess.py", line 626, in check_output
**kwargs).stdout
File "/Users/kaswani/anaconda/envs/aws/lib/python3.5/subprocess.py", line 693, in run
with Popen(*popenargs, **kwargs) as process:
File "/Users/kaswani/anaconda/envs/aws/lib/python3.5/subprocess.py", line 947, in __init__
restore_signals, start_new_session)
File "/Users/kaswani/anaconda/envs/aws/lib/python3.5/subprocess.py", line 1551, in _execute_child
raise child_exception_type(errno_num, err_msg)
FileNotFoundError: [Errno 2] No such file or directory: 'aws'
I have not been able to debug it. Subprocess works just fine for basic commands like ls etc
Using, shell=True makes is work, i.e. subprocess.check_output(['aws','s3','cp','/Users/kaswani/tips.csv','s3://dplearn/'], shell=True)

can any body help? I get this error, and I cant solve it?

I am tring to run a python file and it start but after that give me this error. What I have to do to fixed this error, I am beginner with python.
Traceback (most recent call last):
File "./mininet_multicast_pox.py", line 318, in <module>
mcastTest(topo, False, hosts)
File "./mininet_multicast_pox.py", line 53, in mcastTest
pox_process = Popen(pox_arguments, stdout=fnull, stderr=fnull, shell=False, close_fds=True)
File "/usr/lib/python2.7/subprocess.py", line 710, in __init__
errread, errwrite)
File "/usr/lib/python2.7/subprocess.py", line 1327, in _execute_child
raise child_exception
OSError: [Errno 2] No such file or directory
You have to provide an absolute path to you file.
Without that, the subprocess module can't find it.
The os module provides routine for that.

Call shell script from python

Attempting to call a shell script with options from a python script.
The line ./dropbox_uploader.sh -s download /test/pictures pictures/ runs fine via SSH but errors when called from a python script:
import subprocess
subprocess.call(['./dropbox_uploader.sh -s download /test/pictures pictures/'])
Here is the error message:
Traceback (most recent call last):
File "sync.py", line 2, in <module>
subprocess.call(['./dropbox_uploader.sh -s download /test/pictures pictures/'])
File "/usr/lib/python2.7/subprocess.py", line 493, in call
return Popen(*popenargs, **kwargs).wait()
File "/usr/lib/python2.7/subprocess.py", line 679, in __init__
errread, errwrite)
File "/usr/lib/python2.7/subprocess.py", line 1259, in _execute_child
raise child_exception
OSError: [Errno 2] No such file or directory
In case if the first argument of subprocess.call is a list, it must contain the executable and arguments as separate items:
subprocess.call(['./dropbox_uploader.sh', '-s',
'download', '/test/pictures', 'pictures/'])
or, maybe, more convenient:
import shlex
cmd = './dropbox_uploader.sh -s download /test/pictures pictures/'
subprocess.call(shlex.split(cmd))
There is also an option to delegate parsing and execution to the shell:
cmd = './dropbox_uploader.sh -s download /test/pictures pictures/'
subprocess.call(cmd, shell=True)
(But please note the security warning)

Script giving error of permission denied OSerror 13 from cronjob?

I have written a script from the Python to automate scan. I have used nessus for that and used subprocess module in python. Problem is this it's running from the cli bash, but when I put that script to launch through by cron job. It gives following error
Traceback (most recent call last):
File "/root/nessusscan.py", line 9, in <module>
subprocess.call(['nessus','-q','-x','-T','nessus','127.0.0.1','1241','user','password','ip.txt','res'])
File "/usr/lib/python2.7/subprocess.py", line 493, in call
return Popen(*popenargs, **kwargs).wait()
File "/usr/lib/python2.7/subprocess.py", line 679, in __init__
errread, errwrite)
File "/usr/lib/python2.7/subprocess.py", line 1249, in _execute_child
raise child_exception
OSError: [Errno 13] Permission denied
The script is
subprocess.call(['nessus','-q','-x','-T','nessus','127.0.0.1','1241','user','password','ip.txt','res'])
Command for cron job
16 14 * * * cd /root/nessus; ./nessusscan.py
The error means that the program is found by subprocess but the user running the "nessusscan.py" does not have permissions to run it.
Check ownership of the nessus file and the permissions on it.

Categories

Resources