Python interface wifi.Cell.all(Interface) giving system error - python

I am trying to connect to the wireless network using wifi. As per the documents I have written the code, but it gives system error that file not found. As I can see the argument description of the Cell.all() is interface but we are providing literal as argument. What might be the problem?
import time
import datetime
from wifi import Cell, Scheme
while True :
print datetime.datetime.now()
print Cell.all('wlan0')
time.sleep(5)
>>>
2015-01-25 12:38:43.784000
Traceback (most recent call last):
File "D:\Documents\Development\Script\AutoLogon.py", line 9, in <module>
print Cell.all('wlan0')
File "C:\Python27\lib\site-packages\wifi\scan.py", line 29, in all
stderr=subprocess.STDOUT)
File "C:\Python27\lib\subprocess.py", line 537, in check_output
process = Popen(stdout=PIPE, *popenargs, **kwargs)
File "C:\Python27\lib\subprocess.py", line 679, in __init__
errread, errwrite)
File "C:\Python27\lib\subprocess.py", line 896, in _execute_child
startupinfo)
WindowsError: [Error 2] The system cannot find the file specified
>>>

The python interface wifi was developed for Linux. I may be able to use the library using cygwin.

Related

OSError: [Errno 2] No such file or directory with python2.7/subprocess.py

I am trying to use a Python scrip that converts Latex to a png. The library is at https://github.com/cptdeadbones/pytex2png.
When I run the command python examples.py I get the following error:
Traceback (most recent call last):
File "./examples.py", line 14, in <module>
main()
File "./examples.py", line 11, in main
pytex2png.convert("examples/"+file,"output/"+file+".png")
File "/Users/kekearif/Desktop/pytex2png-master/pytex2png.py", line 44, in convert
make_transparent_bg(output,display)
File "/Users/kekearif/Desktop/pytex2png-master/pytex2png.py", line 31, in make_transparent_bg
exe_command(command_line)
File "/Users/kekearif/Desktop/pytex2png-master/pytex2png.py", line 11, in exe_command
p = subprocess.Popen(args,stdout=subprocess.PIPE)
File "/usr/local/Cellar/python/2.7.13/Frameworks/Python.framework/Versions/2.7/lib/python2.7/subprocess.py", line 390, in __init__
errread, errwrite)
File "/usr/local/Cellar/python/2.7.13/Frameworks/Python.framework/Versions/2.7/lib/python2.7/subprocess.py", line 1024, in _execute_child
raise child_exception
OSError: [Errno 2] No such file or directory'
What does this error mean? Is it an error in how the arguments are being passed?
From the source:
def exe_command(cmd, display=False):
args = shlex.split(cmd)
if(display):
p = subprocess.Popen(args)
else:
p = subprocess.Popen(args,stdout=subprocess.PIPE)
p.wait()
Is there a mistake in the function above?
I hope you have followed the Usage as describe here : Usage which create Makefile.
Have you check the Disclaimers ?? It says the following :
This code was devloped and tested on a Linux based system. I have no
idea if it will work on another system. If you have tested it on
another system, please let me know.

python: trouble with Popen FileNotFoundError: [WinError 2]

I've search a while and still can not figure it out...
Here's part of my code that went wrong.
import subprocess as sp
import os
cmd_args = []
cmd_args.append('start ')
cmd_args.append('/wait ')
cmd_args.append(os.path.join(dirpath,filename))
print(cmd_args)
child = sp.Popen(cmd_args)
And the command prompt through out this.
['start ', '/wait ', 'C:\\Users\\xxx\\Desktop\\directory\\myexecutable.EXE']
Traceback (most recent call last):
File "InstallALL.py", line 89, in <module>
child = sp.Popen(cmd_args)
File "C:\Python34\lib\subprocess.py", line 859, in __init__
restore_signals, start_new_session)
File "C:\Python34\lib\subprocess.py", line 1114, in _execute_child startupinfo)
FileNotFoundError: [WinError 2]
It looks like the filepath is wrong with 2 backslashes.
I know if I do
print(os.path.join(dirpath,filename))
It'll return
C:\Users\xxx\Desktop\directory\myexecutable.EXE
I'm sure the file is there.
How can I debug this?
This is happening because Popen is trying to find the file start instead of the file you want to run.
For example, using notepad.exe:
>>> import subprocess
>>> subprocess.Popen(['C:\\Windows\\System32\\notepad.exe', '/A', 'randomfile.txt']) # '/A' is a command line option
<subprocess.Popen object at 0x03970810>
This works fine. But if I put the path at the end of the list:
>>> subprocess.Popen(['/A', 'randomfile.txt', 'C:\\Windows\\System32\\notepad.exe'])
Traceback (most recent call last):
File "<pyshell#53>", line 1, in <module>
subprocess.Popen(['/A', 'randomfile.txt', 'C:\\Windows\\System32\\notepad.exe'])
File "C:\python35\lib\subprocess.py", line 950, in __init__
restore_signals, start_new_session)
File "C:\python35\lib\subprocess.py", line 1220, in _execute_child
startupinfo)
FileNotFoundError: [WinError 2] The system cannot find the file specified
Use this instead:
import subprocess as sp
import os
cmd_args = []
cmd_args.append(os.path.join(dirpath,filename))
cmd_args.append('start ')
cmd_args.append('/wait ')
print(cmd_args)
child = sp.Popen(cmd_args)
You might need to swap cmd_args.append('start ') and cmd_args.append('/wait ') around too depending on which order they are meant to be in.
I faced the same problem and just to add a note about Popen: As argument Popen takes a list of strings for non-shell calls and only a string for shell calls.
Details listed here: WinError 2 The system cannot find the file specified (Python)

Calling Popen in Python on a MAC - Error can not find file

When I try to shell out of my Python 3.51 program to run the Popen command I get the following errors. Yet when I copy the exact string I'm passing to Popen to the Terminal command line it works fine and opens the file in Adobe Reader which is my default app for the .pdf files.
Here is the Code:
finalCall = r'open /Users/gbarnabic/Documents/1111/combined.pdf'
print(finalCall)
pid_id = subprocess.Popen(finalCall).pid
Here is the error:
open /Users/gbarnabic/Documents/1111/combined.pdf
Exception in Tkinter callback
Traceback (most recent call last):
File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/tkinter/init.py", line 1549, in call
return self.func(*args)
File "pdfcomb2.py", line 212, in change_dir
self.openPDF(outFileName, pageNum)
File "pdfcomb2.py", line 426, in openPDF
subprocess.run(finalCall)
File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/subprocess.py", line 696, in run
with Popen(*popenargs, **kwargs) as process:
File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/subprocess.py", line 950, in init
restore_signals, start_new_session)
File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/subprocess.py", line 1544, in _execute_child
raise child_exception_type(errno_num, err_msg)
FileNotFoundError: [Errno 2] No such file or directory: 'open /Users/gb/Documents/1111/combined.pdf'
Georges-MBP:filepicktest gb$ open /Users/gb/Documents/1111/combined.pdf
Georges-MBP:filepicktest gb$
With Popen you need to set shell=True to pass command as a string or split command in a list of arguments. Could be done with shlex
import shlex
import subprocess
subprocess.Popen(shlex.split('open ....'))
You could check example in documentation:
https://docs.python.org/2/library/subprocess.html#subprocess.Popen
So the error here means that Python try to run file with name open /Users/gb/Documents/1111/combined.pdf. Obviously it doesn't exist

python exception error subprocess file missing - but what file?

i have a code running on python 2.7.3 (windows) and i try to run it on python 2.7.8(windows) and get the following error:
main : INFO ** Starting Main **
Traceback (most recent call last):
File "C:\wamp\www\prenderer\src\main.py", line 82, in <module>
nuke_process = launch_nuke()
File "C:\wamp\www\prenderer\src\main.py", line 31, in launch_nuke
query = subprocess.Popen(r"query process", stdout=subprocess.PIPE)
File "F:\python27\lib\subprocess.py", line 710, in __init__
errread, errwrite)
File "F:\python27\lib\subprocess.py", line 958, in _execute_child
startupinfo)
WindowsError: [Error 2] The system cannot find the file specified
>>>
what is wrong?
Pass shell=True argument:
query = subprocess.Popen(r"query process", stdout=subprocess.PIPE, shell=True)
or pass the command line argument as a list:
query = subprocess.Popen(["query", "process"], stdout=subprocess.PIPE)
Otherwise query process is recognized as a program instead of query.

Compiling and Executing Java file in python

how can I open an java file in python?, i've search over the net and found this:
import os.path, subprocess
from subprocess import STDOUT, PIPE
def compile_java (java_file):
subprocess.check_call(['javac', java_file])
def execute_java (java_file):
cmd=['java', java_file]
proc=subprocess.Popen(cmd, stdout = PIPE, stderr = STDOUT)
input = subprocess.Popen(cmd, stdin = PIPE)
print(proc.stdout.read())
compile_java("CsMain.java")
execute_java("CsMain")
but then I got this error:
Traceback (most recent call last):
File "C:\Python33\lib\subprocess.py", line 1106, in _execute_child
startupinfo)
FileNotFoundError: [WinError 2] The system cannot find the file specified
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "C:\casestudy\opener.py", line 13, in <module>
compile_java("CsMain.java")
File "C:\casestudy\opener.py", line 5, in compile_java
subprocess.check_call(['javac', java_file])
File "C:\Python33\lib\subprocess.py", line 539, in check_call
retcode = call(*popenargs, **kwargs)
File "C:\Python33\lib\subprocess.py", line 520, in call
with Popen(*popenargs, **kwargs) as p:
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
>>>
the python file and java file is in the same folder, and I am using Python 3.3.2, how can I resolve this? or do you guys have another way on doing this?, any answer is appreciated thanks!
I think it isn't recognizing the javac command. Try manually running the command and if javac isn't a recognized command, register it in your PATH variable and try again.
Or you could just try typing the full pathname to the Java directory for javac and java.
you need to add path to your java file name. like this:
compile_java("C:\\path\to\this\CsMain.java")

Categories