I am trying to check video integrity and made it successfully using mac terminal with the line of code below:
ffmpeg -v error -i filename.mp4 -f null - 2>error.log
Now i am trying to do the same in python with no success making the cmd command. I try to do:
cmds = ["ffmpeg", "-i","filename.mp4", "-v", "error", "-f", "null", "-", "2>", "error.log"]
subprocess.Popen(cmds)
But i am getting the error - 2>: Invalid argument
I also tried also "2>error.log" instead of "2>", "error.log" but then im getting 2>error.log: Invalid argument
I found a work around to fix the problem.I am running the command with python from the terminal using:
import os
os.system("ffmpeg -v error -i filename.mp4 -f null - 2>error.log")
log_file = open("error.log","r")
print log_file.read()
Related
I'm trying to run a python file from within my python script. I'm doubtful that the file is even getting run in the first place and it is not showing anything in the stdout either for me to debug.
I have tried the command 'ls' in subprocess and it worked, and was in the proper directory that the temp.py file i am trying to run is.
When i have tried to set the argument 'shell=True' it takes me into the python repl for some reason i am not sure why.
Here is the string output:
Terminal output: CompletedProcess(args=['python3', 'temp.py'], returncode=0, stdout=b'')
And here's the code used to produce it:
result = subprocess.run(['python3', 'temp.py'], stdout=subprocess.PIPE, check=True)
print('Terminal output: '+str(result))
EDIT
I also just tried
process = Popen(['python3', 'temp.py'], stdout=PIPE, stderr=PIPE)
stdout, stderr = process.communicate()
print('Terminal output: '+str(stdout)+str(stderr))
No cigar:
Terminal output: b''b''
So, I found an alternative that worked. I dumped all the contents of the file into the python3 command with the '-c' augment.
process = Popen(['python3','-u', '-c', strCode], stdout=PIPE, stderr=PIPE)
strCode being the contents of the file.
I'm developing a C++ library that has a piece of shell script code that return the name of a specific serial port. When I run this script in console either X64 desktop or Arm enviorment the script returns the right answer. My problem ocur when I execute the same script inside of the library, the returns shows bad formed string like ÈÛT¶ÈÛT¶¨a , but the expected is /dev/ttyACM0.
The script that run inside of library:
Script
bash -c 'for sysdevpath in $(find /sys/bus/usb/devices/usb*/ -name dev);do(syspath="${sysdevpath%/dev}";devname="$(udevadm info -q name -p $syspath)";[[ "$devname" == "bus/"* ]]&& continue;teste="$(udevadm info -q property --export -p $syspath | grep -i "company_name")";if [[ ! -z "${teste// }" && $devname == *"ttyACM"* ]]; then echo "/dev/$devname";fi);done;' 2> /dev/null
The following piece of code is used to save the content returned by the script into a file.
code c++
pfFile = fopen(CONFIG_FILE, "w+");
fwrite(result,strlen(result), 1, pfFile);
fclose(pfFile);
return 0;
Besides you didn't include what is result and where it comes from in your C++ code; you selected the hardest way to do this. Code running shell scripts inside a library most likely cause nothing but headaches.
Basically you can create an udev rule for your device to create an unique and stable file in /dev to access it. You can create one like this one in the ArchWiki
KERNEL=="video[0-9]*", SUBSYSTEM=="video4linux", SUBSYSTEMS=="usb", ATTRS{idVendor}=="05a9", ATTRS{idProduct}=="4519", SYMLINK+="video-cam1"
I have created a GUI that runs a command in Linux Terminal.
EXAMPLE=> -n 20 -id 15 -domain square(10,20) -dim 2 -o execution -format geo,tess
This command is for the execution of a code for package. And when it executes a series of outputs undergo in the Linux terminal. The output is either successful and the output is generated or an error occurs due to a dump error or bad argument.
Examples of Terminal Outputs:
Error : matheval failed to process the expression. The expression
syntax is probably incorrect. This may also be caused by an unproper
matheval installation (expression = 1 -ori fibre(,,)). Aborted (core
dumped)
Another Error
Error : Bad arguments!
Aborted (core dumped)
What i am trying to do is return this error back into the GUI as either a MessageBox and/or update the bottom Status bar of the GUI with the error.
I am not familiar with the wx and subprocess modules, but my research so far has failed to find a solution.
I am running Python 2.7 and using Tkinter.
This seems to get the work done.
# Create a string and pass variables
neper_exec = "neper -T -n %s -id %s -format %s -o %s -dim %s -domain %s " % (n, id, output_form, o, dim, domain)
# Execute the subporcess using the variable
p = subprocess.Popen(neper_exec, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE) # when shell is dropped Linux gives and error
Thanks to #BrianMcFarland for guidance on the subprocess command.
I am using terminal to sucsessfully open a file in quicktime player 7, but can't seem to get it working using python to do the same thing.
So this is working from terminal:
open -a "Quicktime Player 7" /Users/Me/Movies/test.mov
But this is not working in python 2.7, it opens quicktime, but not the file:
command = ('open -a "Quicktime Player 7"', 'Users/Me/Movies/test.mov')
subprocess.Popen(command, shell=True)
What am I doing wrong?
If you pass command as list/tuple, you have to split the arguments up correctly:
command = ('open', '-a', 'Quicktime Player 7', '/Users/Me/Movies/test.mov')
subprocess.Popen(command, shell=True)
Then I think you should also be able to drop the shell=True parameter. Further, you could look into subprocess.call() or subprocess.check_call() (the former returns the return value of the program, the latter raises an exception if the return value indicates an error):
subprocess.check_call(['open', '-a', 'Quicktime Player 7', '/Users/Me/Movies/test.mov'])
NB: Coding-style-wise, command is usually passed as list, as seen in the docs I linked above.
Edit: Add '/' at the beginning of both paths to make it work.
So I am running on 64-bit Windows 7, and I set up Pyinstaller with Pip and PyWin32. I have python 2.7.
I made a simple hello world Program with this code
print "hello world!"
I put the file in the same directory as PyInstaller, and ran this code in the command prompt
pyinstaller.py helloWorld.py
Yet, when I try that, I get this error message:
Error loading Python DLL: C:\PROGRA~1\PYINST~1.1\build\HELLOW~1\python27.dll (error code 126)
What am I doing wrong and how do I fix this?
Run with the -F flag to produce the standalone exe:
pyinstaller -F helloworld.py
It will output to dist/helloworld.exe
NOTE this is a different location to when -F is not used, be sure to run the right exe afterwards.
Thanks #tul! My version of pyinstaller put it to dist\helloworld.exe though!
If you start it from C:\Python27\Scripts... that'll be C:\Python27\Scripts\dist... as well!
But whereever you have it, I recommend putting a batch file next to your .py to be able recompile any time with just a click:
I set it up so there is nothing but the .exe at the .py location and the temporary stuff goes to the temp dir:
#echo off
:: get name from filename without path and ext
set name=%~n0
echo ========= %name% =========
:: cut away the suffix "_build"
set name=%name:~0,-6%
set pypath=C:\Python27\Scripts
set buildpath=%temp%
if not exist %name%.py (
echo ERROR: "%name%.py" does not exist here!
pause
exit /b
)
%pypath%\pyinstaller.exe --onefile -y %~dp0%name%.py --distpath=%~dp0 --workpath=%buildpath% --specpath=%buildpath%
I name it like the .py file plus "_build" and cut away the suffix in the batch script again.
Voilà.