Calling an executable

Scripting in Blender with Python, and working on the API

Moderators: jesterKing, stiv

Post Reply
michael75
Posts: 0
Joined: Tue Jul 09, 2013 4:58 pm

Calling an executable

Post by michael75 »

Iv tried to find info on this but no joy. Basically i have a simple c# exe that opens loads an image, resizes it and save it before closing, very simple.
Iv tried the popen and subprocess.call with and without shell and i get nothing on the console as an error but the exe did not execute.

So i made a .bat file calling the exe, which i tested and it works but when i call that from script i get a windows "cannot find file...." message.

So guessing maybe python doesnt like my paths i put the whole lot on the root but still it wont run.

Iv tested other exe's on the root and in folders and they run ok.

My exe is just a form with a picturebox and about 3 line of code on the form_load.

stiv
Posts: 0
Joined: Tue Aug 05, 2003 7:58 am
Location: 45N 86W

Post by stiv »

Iv tried the popen and subprocess.call with and without shell
At the risk of being Captain Obvious, likely you are doing something wrong. Hard to say what exactly without some code.

michael75
Posts: 0
Joined: Tue Jul 09, 2013 4:58 pm

Post by michael75 »

stiv wrote:
Iv tried the popen and subprocess.call with and without shell
At the risk of being Captain Obvious, likely you are doing something wrong. Hard to say what exactly without some code.
haha yes i believe so, and my god i hope your right as my brain died 10 hours ago :(


subprocess.Popen(["path to the file.exe"])
subprocess.call(["Path to file.exe"], shell = True)

iv tried this, havent the exact code as it was just a test on a blank script but as i say it worked fine on other exes in the folder or elsewhere seems like python doesnt like a simple compile from c#?

Also im baffled why the batch file works from explorer but not script.

Im using blender 6.7 and alot on the web is for older versions. But i would presume i have to pass something other than "call" to my file or my file needs some kind of property or value it doesnt. If somebody had c# maybe they could try.

stiv
Posts: 0
Joined: Tue Aug 05, 2003 7:58 am
Location: 45N 86W

Post by stiv »

(["path to the file.exe"])

My guess: your path has backslashes ( the \ char) in it. A number of backslash/single-character combinations are ASCII escape sequences for things like a tab (\t) or a new line (\n). These will mess up your file path.

Windows does (or did!) recognize the forward slash (/) as a valid separator. If you have something like "C:\this\will\not\work.exe", try changing it to "C:/this/will/not/work.exe".

Or build paths with the os.path module.

michael75
Posts: 0
Joined: Tue Jul 09, 2013 4:58 pm

Post by michael75 »

Yeah i copped the \\ trick, but it seemed that my exe was at fault. I recreated it giving it complete properties and then published it and i could then call it.

My next problem is sending a command line to the exe, it seems that

os.popen(["c:\\Myexe.exe mycommand"])

is seen as literal file path as is get a file not found issue.

Is it possible to send a command line string in bpy? if not i can work around but it would be the best option for me.

michael75
Posts: 0
Joined: Tue Jul 09, 2013 4:58 pm

Command line Arguments

Post by michael75 »

Ok first thanks stiv for repling to my noob questions.

Ok so iv found out that popen is structured as:

os.popen(["c:\\test\\app.exe","/s"])

so that you can pass the command "/s" to app.exe just incase anyone else has this issue.

stiv
Posts: 0
Joined: Tue Aug 05, 2003 7:58 am
Location: 45N 86W

Post by stiv »

Glad it is working for you! And thanks for reporting back. I'm sure that will help someone else.

Post Reply