Subprocess module Python - python

We have an issue using the subprocess library in Python. We tried to pass 2 message with the function communicate. The first one work correctly, but the second one generates a IOError
error. I think that we probably use incorrectly the function of the subprocess library, but we are not able to fix it.
Can anyone help us?
Here is the code:
from subprocess import *
video=Popen("omxplayer myvideo.mp4",shell=True,stdout=PIPE,stdin=PIPE)
video.stdin.write('+')
video.stdin.flush()
result=video.stdout.read()
print "Vol +: "+result
video.communicate('p')
print "Pause"
And the error:
Traceback (most recent call last):
File "youtube.py", line 55, in <module>
proc.stdin.write('+')
IOError: [Errno 32] Broken pipe
Thank you

Related

AttributeError: expected a callback function (and optionally one or two strings) as argument(s)

I'm new to Python and was trying to do some import and export scripting in Blender 2.43(which uses Python 2.4).
I had a simple script:
import Blender
import flt_import
import export_obj
import os
select_file=flt_import.select_file(r'C:\Code\Code\Testing4Flt\sg_navysoldier.flt')
Blender.Window.FileSelector(select_file, "Import OpenFlight", "*.flt")
out_file=export_obj.write_ui(r'C:\Code\Code\Testing4Flt\sg_navysoldier.obj')
Blender.Window.FileSelector(out_file,'Export Wavefront OBJ', sys.makename(ext='.obj'))
When run, I got the error in the title at line 8. I don't really understand what it means and I tried searching it but couldn't find that error exactly. Will appreciate any help.
Edit:
Here's the full traceback.
Traceback (most recent call last):
File "Testing4.py", line 8, in ?
AttributeError:
expected a callback function (and optionally one or two strings) as argument(s)

Python print() throws an invalid handle after call into dll

Using ctypes to import a DLL. Occasionally, after a function from the dll is called and I call the print() function in Python, I get an OS Error: Invalid handle.
The calls to the dll are successful and 90% of the time the application works without a hitch. Every 10 runs this exception will throw and I can't even catch it properly since I don't have a way to restore the handle.
I'm think the dll is somehow messing with the stdout handle that print() uses. There are some functions within the dll that still print to stdout. Is there any way to reacquire a valid handle?
Traceback (most recent call last):
File "{PATH}/demo.py", line 13, in <module>
print(" ")
OSError: [WinError 6] The handle is invalid
Exception ignored in: <_io.TextIOWrapper name='<stdout>' mode='w' encoding='utf-8'>
OSError: [WinError 6] The handle is invalid
Issue has been fixed by duplicating the stdout handle using os.dup2()
# Duplicate stdout
stdout_copy = 0
os.dup2(sys.stdout.fileno(), stdout_copy)
# Restore stdout
sys.stdout = os.fdopen(stdout_copy,"w")

Syntax Error in python Wifi Module

So I am trying to use python's wifi module to get neary wireless networks and log into them using a password. So far this is my code just to get the networks...
from wifi import Cell, Scheme
Cell.all('interfacename')
And I am receiving the following error...
Traceback (most recent call last):
File "python", line 1, in <module>
File "/goval_modules/python3.6/pbkdf2/__init__.py", line 69
print pbkdf2(p, s, l, i).encode('base64')
^
SyntaxError: invalid syntax
Can someone please help me understand why this error is appearing and how to fix it?
As Kanak mentioned, this WiFi module was written in python2, but you are using it in python3. Unfortunately, there is no workaround for this.
One possible fix could be trying to find an updated version of this module. You could also write your code in python2, but that might be a bit impractical.

Using osmviz in Python

I am trying to use the osmviz module of Python, which allows to use maps from OpenStreetMap.
So I downloaded it with pip, and then I tried to run one of the examples offered by the documentation page of osmviz (https://hugovk.github.io/osmviz/html/doc.html), the third one (https://hugovk.github.io/osmviz/html/pil_example.py.html).
However it doesn't work, I keep getting the following error :
Traceback (most recent call last):
File "testosm.py", line 1, in <module>
from osmviz.manager import PILImageManager, OSMManager
File "/home/FUNDP/mcohilis/.local/lib/python3.4/site-packages/osmviz/manager.py", line 60
raise Exception, "UNIMPLEMENTED"
^
SyntaxError: invalid syntax
So the error seems to be inside the module code and is a syntax error, which I find very weird. What could I do about it?
I get the same error with another code using osmviz, and I tried with two different computers, it doesn't change anything.
Does someone know how to use osmviz ?
Thanks a lot,
Marie

Python 3.4 accessing stdout

Apologies for my ineptness. When I run the following in IDLE on my python 3.4 install it fails.
>>> sys.stdout.fileno()
Traceback (most recent call last):
File "<pyshell#23>", line 1, in <module>
sys.stdout.fileno()
io.UnsupportedOperation: fileno
This, seems to give something useful though...
>>> sys.stdout.fileno
<built-in method fileno of PseudoOutputFile object at 0x030927D0>
What obvious thing am I doing wrong?
thanks.
to cut a long story short I am actually trying to do this:
import os
os.write(1, "Hello world!\n")
But got the following error, so went down the route of trying out stdout
Traceback (most recent call last):
File "<pyshell#34>", line 1, in <module>
os.write(1, "Hello world!\n")
TypeError: 'str' does not support the buffer interface
and so the call to print sys.stdout.fileno() would give me the number, and I thought it might just be that it shouldn't be 1.
IDLE under windows is started with pythonw.exe, a console-less GUI. As such there is no stdout handle assigned, at all.
The shell window itself needs to redirect all stdout output to the GUI window, which is the PseudoOutputFile object you see.
If you wanted to experiment with writing to the 1 filenumber, you need to start IDLE with a console attached:
py -m idlelib
from a console should be enough to give you a process with an actual sys.__stdout__ file handle, and writing with os.write(1, ...) will work.
Do remember that writing directly to a file handle requires bytes, not Unicode text. Encode your text or use a b'...' bytes literal.

Categories

Resources