Error from tshark and python - python

I am trying to execute this simple tshark command through python but I am not able to succeed and I don't understand the error
OS : Windows 7
Python 3.3
Code is
from subprocess import Popen
f = open("C:\\folder2\\test.txt","w")
Popen(["tshark" ,"-r","C:\\folder2\\fvido.pcap","-qz", "io,stat,0"],stdout=f)
and the error I get is
Traceback (most recent call last):
File "C:/Users/pc/Google Drive/Python/tshark1.py", line 6, in <module>
Popen(["tshark" ,"-r","C:\\folder2\\fvido.pcap","-qz", "io,stat,0"],stdout=f)
File "C:\Python33\lib\subprocess.py", line 820, in __init__
restore_signals, start_new_session)
File "C:\Python33\lib\subprocess.py", line 1112, in _execute_child
raise WindowsError(*e.args)
FileNotFoundError: [WinError 2] The system cannot find the file specified

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)

UNIX Command within Python Script receiving an error. Script executes command does not

I have a python script. On top of the script "from subprocess import call". If I write "call(["whoami"])" in the script and I execute the Python script from the unix command line it works, my username returns. But if I run a proprietary command with arguments, "call(["mi_xx", "-s", "20141215","-e","20150121","-p",'TX%_XX%',"-f","test","-i","-x","-d"])"
I get the error below. I run the same command directly in unix and it works. I have searched up and down. The python environment in unix is fine.
Error
Traceback (most recent call last):
File "Mixx.py", line 44, in <module>
call(["mi_xx", "-s", "20141215","-e","20150121","-p",'TX%_XX%',"-f","test","-i","-x","-d"])
File "/bb/util/common/ActivePythonEE_2.6.2_32bit/lib/python2.6/subprocess.py", line 444, in call
return Popen(*popenargs, **kwargs).wait()
File "/bb/util/common/ActivePythonEE_2.6.2_32bit/lib/python2.6/subprocess.py", line 595, in __init__
errread, errwrite)
File "/bb/util/common/ActivePythonEE_2.6.2_32bit/lib/python2.6/subprocess.py", line 1092, in _execute_child
raise child_exception
OSError: [Errno 2] No such file or directory"

subprocess call errors in python

I have been having problems with subprocess call.
I wrote a very simple code (test.py) that simply prints "Hello….."
Then I did the following:
/sw/bin/python2.7
import subprocess
call (["test.py"])
I got the following error:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/sw/lib/python2.7/subprocess.py", line 522, in call
return Popen(*popenargs, **kwargs).wait()
File "/sw/lib/python2.7/subprocess.py", line 709, in __init__
errread, errwrite)
File "/sw/lib/python2.7/subprocess.py", line 1326, in _execute_child
raise child_exception
OSError: [Errno 2] No such file or directory
I can get it to work with os.system but I am keen to learn this subprocess method.
Where am I going wrong?
The test.py being called is in the same folder.
Try this:
subprocess.call(["python", "test.py"])

python subprocess throws error "no such file or direcrory"

s=subprocess.Popen(['/home/karthik/Downloads/stanford-parser-2011-06-08/lexparser.csh','-'],stdin=subprocess.PIPE,stdout=subprocess.PIPE,stderr=subprocess.PIPE)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/lib/python2.7/subprocess.py", line 672, in __init__
errread, errwrite)
File "/usr/lib/python2.7/subprocess.py", line 1213, in _execute_child
raise child_exception
OSError: [Errno 2] No such file or directory
I'm sure this file exists and open() with this filename works.Why am i getting this error ? i use python 2.7
Make sure csh is installed and is in /bin/csh (otherwise edit the command after the shebang in lexparser.sh).

Categories

Resources