python subprocess call to irfanview fails - python-2.7

I'm attempting to get Irfanview to extract some multipage images for me. As you can't batch do that operation within Irfanview I'm trying to use Pythons subprocess.call() to do the commandline work for me.
I've got the command in powershell working fine with no issues. But when I try the exact same command via subprocess.call() Irfanview tells me I've got an "unsupported save type !"
PS command:
i_view32.exe .\multiPage.tif /extract=(".\,tif")
Python code:
cmd = r'i_view32.exe .\multiPage.tif /extract=(".\,tif")'
subprocess.call(cmd, shell=True)
I've tried with no shell too. Also I tried giving it fully qualified names. No difference.
Any ideas?
Cheers,
James

Ahh. I've found the problem. Turns out in PS I need to give the extract folder path as a string whereas via Python I don't.
So in Py instead of
i_view32.exe .\multiPage.tif /extract=(".\,tif")
It needed to be
i_view32.exe .\multiPage.tif /extract=(.\,tif)
Thats actually the same way that the Irfanview manual asks for it. No idea why PS demanded the string bit.

Related

Stata do files in Atom (script package)

I am trying to run a do file in Atom (macOS). The script package detects the language correctly but is "unable to run".
Atom is started from the terminal, script works for other languages and Stata is on PATH.
Any idea what might be going wrong?
Just to note, the issue can also be solved on Windows by editing grammars.coffee as well, the default path being C:/Users/*username*/.atom/packages/script/lib/ and changing "stata" to the location of Stata on the machine. Highlighted text also doesn't work, as each line is executed in Stata with quotes around it, meaning Stata will interpret it as a single command name, not as a command with arguments.
Figured it out: .
The code of the script package needs to be modified. In the grammars.coffee file, I replaced both commands of Stata by "/Applications/Stata/StataSE.app/Contents/MacOS/StataSE". Works fine now.
Adding Stata to the path variable is not sufficient (might not be necessary even).
This works for me too — but I use StataMP so updated the filepath as such to /Applications/Stata/StataMP.app/Contents/MacOS/StataMP and things are working fine now.
That said, I'm not sure if script supports this, but when executing a highlighted selection of code in a .do file crashes my StataMP 14.2

Running Python programs in python.exe, the command prompt, and IDLE

Let me preface this post that I am incredibly new to python. I took a course in codeacademy but haven't actually used python on my own computer until now. Let me also explain to everyone that my coding experience is limited to VBA and excel. I have very little knowledge of how to use the command prompt, how libraries work, etc, etc.
I'm having some issues. I've changed my directory to recognize python when I type python in my command prompt. Then I can do simple things like
print "hello"
however if i write something like this
def firstfunction(t):
print t+5
return
firstfunction(5)
I would expect this to print the number 10, however I get the following error:
File"stdin", line 4
first function(5)
^
syntaxerror: invalid syntax
However if I use this in IDLE and run it it works fine.
Next I've saved some python programs I wrote. One I saved as Hello.py
i want to run this code from my python exe or from the command prompt but can't figure out how.
Please any answers helpful, if you use computer lingo, try and keep it as simple as possible. I'm super new!
Thanks
If the location of python is not included in your path, add it. But in any case, you should be able to run this successfully from the directory containing your python.exe.
e.g, if python lives in C:\Python27:
cd C:\Python27
python mypythonscript.py

Creating and running a file with command line arguments

I am very new to linux and apologize if my descriptions are not savvy. I will try to be relevantly detailed.
Currently I am working on a terminal using Fedora, and my goal is to create a smaller data set to run a program. I was given an example, and my mentor said that to run the program all I had to do was type "./filename" into the console.
filename has command line arguments as follows: "./main ./textfile1 ./textfile2" Basically, each argument is separated by a space.
I tried recreating this document with similar format, but I am not sure what to save it as, nor does it work when I try running it the same way as the file with a larger data set.
Also, filename is bold in the terminal, whereas the document I created it is not. I'm not sure if this helps at all, but it is a difference I noticed.
Any help would be appreciated.
You need to set the execute bit on your file.
chmod +x filename
Make sure you compile the program first (in case you haven't. I use the g++ compiler typically) and then use the ./filename like your instructor said, but do not put "./" in front of the arguments. Just write it as "./filename textfile1.txt textfile2.txt"

Enthought Canopy User Input

I'm using Enthought Canopy on Mac OSX Lion. I'm using this because of the ease at which modules and libraries can be downloaded and installed (had a lot of trouble downloading pandas and numpy through terminal due to a number of issues).
So, now I'm doing my coding for a project in Canopy, which is OK (still prefer Wing, though). The problem I have encountered is that I need to ask the user for input. When I do, for instance:
x = input('Enter your input here: ')
I get an EOF error as follows: EOFError: EOF when reading a line
I was looking around and believe that this may be something which Canopy does not support. Was wondering if this is, indeed, the case and if there is a solution/workaround to this problem?
I assume that you are entering this code in the IPython shell that is embedded in the Canopy editor. This is an upstream bug/deficiency in IPython's Qt console. Because the remote shell is not actually hooked up to a terminal, functions like input() and raw_input() need to be replaced to get the input from the GUI console widget instead. IPython (and thus Canopy) does replace raw_input() but does not replace input(). This code will work using Canopy's Python interpreter if you were to put it into a script and execute it from the command line, and it would also work in a terminal instance of IPython. It was most likely overlooked because it is usually considered a bad idea to use input().
Please use raw_input() instead and parse the string that you get. You can use eval() if you must, but I do recommend using a more specific parsing/conversion function.

how to get value from spinctrl and send it to .exe file in python script

I am new to python and wxpython, I am making a automated tool using python and for user interface wxpython and i use shell script.shell script can be called from the python. but now I am facing problem with the spinctrl value. whenever that spinctrl value changes it have to send that value into one txt.exe file which is written in BASH .{ if we run txt.exe file in command line it will ask for number then it will accept that value whenever we press enter}. but i am not able to understand that how to send value from spinctrl to txt.exe whenever i press "ok" button in GUI. please share your thoughts and knowledge.
Thank you
To call an executable in Python, you need to look at Python's subprocess module: http://docs.python.org/2/library/subprocess.html
If your exe doesn't accept arguments, then it won't work. If you created the exe yourself using something like PyInstaller or py2Exe, then you need to make it so your app can accept arguments. The simplest way is using sys.argv, but there are also the optparse and argparse libraries in Python as well.
I do not get a good feeling about your concept. It is hard to say, but I suspect you would benefit from talking with someone experienced about what you are trying to achieve and how it could best be done.
However, to get you started down your current path, I think you should take a look at wxExecute ( http://docs.wxwidgets.org/2.8/wx_processfunctions.html#wxexecute ). This will allow you to run your txt.exe utility from inside your GUI.
wxExecute is a wxWidgets utility. If you are working in python then there will be a more direct way to do this using a python utility - some-one else will have to advise on that. I suggest you edit your question for clarity so a python expert can help you.