I need to create a python script that runs a file gams (myfile.gms).
My file is in a folder F:\Otim\correct, so I was using a part of a code that I saw in this forum. I made:
import subprocess
subprocess.check_call(["F:\Otim\correct\myfile.gms"])
and I get an error:
Runtime error
Traceback (most recent call last):
File "<string>", line 80, in <module>
File "C:\Python27\ArcGIS10.2\Lib\subprocess.py", line 506, in check_call retcode = call(*popenargs, **kwargs)
File "C:\Python27\ArcGIS10.2\Lib\subprocess.py", line 493, in call return Popen(*popenargs, **kwargs).wait()
File "C:\Python27\ArcGIS10.2\Lib\subprocess.py", line 679, in __init__errread, errwrite)
File "C:\Python27\ArcGIS10.2\Lib\subprocess.py", line 896, in _execute_child
startupinfo)
WindowsError: [Error 193] %1 is not a valid Win32 application
Can someone help me please? Thanks
I've never used gams but after a quick look at www.gams.com it sounds like myfile.gms is not the file to be executed but the input file to be given as argument to the gams executable.
So you should try something like :
import subprocess
subprocess.check_call([r"C:\path\to\programs\GAMS.exe",r"F:\Otim\correct\myfile.gms"])
Notice : there is a GAMS python API which could give you a more portable solution.
Related
I have a Raspberry PI and I want to automatically open a website at boot time.
So I made an auto start config to run a python (v.3.5.3) script on boot.
The python script looks like this:
import os
import subprocess
subprocess.call([/home/pi/Desktop/Shortcut Final.desktop])
But I get the error:
Traceback (most recent call last): File "/home/pi/myscript.py", line 3
subprocess.call([/home/pi/Desktop/Shortcut Final.desktop])
^ SyntaxError: invalid syntax
I got my instructions from a guide that used windows file location, so I think the error is that my file location dont start with a directory letter like C:, but I dont think raspbian use the same system.
I have not found any other guides that explain how to accomplish the same thing in simple terms (as i only know very basic python coding)
I have looked into the open() command, but it seemed complicated.
Any tips on how to accomplish my goal/solve the error?
After putting the file location in quotes the syntax error disappears and i encounter a new error:
Traceback (most recent call last):
File "/home/pi/myscript.py", line 5, in <module>
subprocess.call(["/home/pi/Desktop/Shortcut Final.desktop"])
File "/usr/lib/python3.5/subprocess.py", line 247, in call
with Popen(*popenargs, **kwargs) as p:
File "/usr/lib/python3.5/subprocess.py", line 676, in __init__
restore_signals, start_new_session)
File "/usr/lib/python3.5/subprocess.py", line 1282, in _execute_child
raise child_exception_type(errno_num, err_msg)
PermissionError: [Errno 13] Permission denied
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.
I want to execute shell command "objdump" using python for my research work
I have used subprocess.call("command") to execute linux command but its not working.
Sample code which i have tried is
import subprocess
subprocess.call("date")
after the execution
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "C:\Python27\lib\subprocess.py", line 168, in call
return Popen(*popenargs, **kwargs).wait()
File "C:\Python27\lib\subprocess.py", line 390, in __init__
errread, errwrite)
File "C:\Python27\lib\subprocess.py", line 640, in _execute_child
startupinfo)
WindowsError: [Error 2] The system cannot find the file specified
You must do this:
subprocess.call('date', shell=True)
Actually, Shell does allow you to access to global variable and programs that are in $PATH and your shell.
Have you tried ?
import subprocess
subprocess.call("date", shell = True)
I'm working with a set of scripts aimed at modifying an android app, the github repo located here: Ingress Broot Mod. I installed Python 3.2, then installed PyYAML 3.10. I moved on to follow the build instructions and "Import Ingress apk using import_apk.py script."
Specifically, I typed: B:\GitHub\ingress-apk-mod\bin>python import_apk.py "B:\com.nianticproject.ingress-1.apk"
At which point this error pops up.
Traceback (most recent call last):
File "B:\GitHub\ingress-apk-mod\bin\import_apk.py", line 28, in <module>
main(sys.argv[1])
File "B:\GitHub\ingress-apk-mod\bin\import_apk.py", line 24, in main
''' % (LINE_PREFIX, apk), shell=True, executable='/bin/bash')
File "C:\Python32\lib\subprocess.py", line 483, in check_call
retcode = call(*popenargs, **kwargs)
File "C:\Python32\lib\subprocess.py", line 470, in call
return Popen(*popenargs, **kwargs).wait()
File "C:\Python32\lib\subprocess.py", line 744, in __init__
restore_signals, start_new_session)
File "C:\Python32\lib\subprocess.py", line 977, in _execute_child
startupinfo)
WindowsError: [Error 3] The system cannot find the path specified
The closest I could find was Unable to run call subprocess method using python 3.2.
Is this an easy fix; if not, what steps should I take to fix this problem?
This is my first time using python - could this possibly stem from improperly installed Python (did I miss a step?)
I am trying to build adblockplus from this link. When I issue the command:
python build.py build
I end up getting the following error message. I tried with and without sudo to no avail.
Traceback (most recent call last):
File "build.py", line 10, in <module>
buildtools.build.processArgs('.', sys.argv)
File "/home/machine/projects/weird/buildtools/build.py", line 352, in processArgs
commands[command](baseDir, scriptName, opts, args, type)
File "/home/machine/projects/weird/buildtools/build.py", line 39, in __call__
return self._handler(baseDir, scriptName, opts, args, type)
File "/home/machine/projects/weird/buildtools/build.py", line 166, in runBuild
limitMetadata=limitMetadata)
File "/home/machine/projects/weird/buildtools/packager.py", line 274, in createBuild
buildNum = getBuildNum(baseDir)
File "/home/machine/projects/weird/buildtools/packager.py", line 80, in getBuildNum
(result, dummy) = subprocess.Popen(['hg', 'id', '-n'], stdout=subprocess.PIPE).communicate()
File "/usr/lib/python2.6/subprocess.py", line 623, in __init__
errread, errwrite)
File "/usr/lib/python2.6/subprocess.py", line 1141, in _execute_child
raise child_exception
OSError: [Errno 2] No such file or directory
Am I missing a package? Any hint on what the problem could be will be much appreciated.
The stack trace makes it clear that the issue is caused by the following line:
(result, dummy) = subprocess.Popen(['hg', 'id', '-n'], stdout=subprocess.PIPE).communicate()
If you look at the subprocess package documentation, this line is trying to run the hg id -n command (get numerical Mercurial revision). Apparently, the Mercurial command line tool isn't present on your system (a possibility that this build script didn't consider) so it fails.
Disclaimer: I happen to be the one who wrote this script and I fixed this bug now. Mercurial isn't essential for the build, the revision number is pretty much only necessary to determine the output file name.