Forums > MaxMSP

How can you run an external file from within a patch?

June 7, 2009 | 3:39 pm

I’m trying essentially to do this:
have my patch run a file outside of the patch when you click a button. So for example I have a button that says "run [x] programme now" and it runs another file on the computer (in this case it is a .cmd file, but it would be also useful if i could do this to e.g. open a pdf file).

Is there a (preferably easy..) way to do this?

Advice appreciated


June 7, 2009 | 3:41 pm

i think what you need is some kind of terminal/dos external

have a look at max objects


June 7, 2009 | 4:44 pm

hi,

you can use the following max message :

;max launchbrowser file:///path/to/any/file

g


June 7, 2009 | 4:44 pm

you might try the launchbrowser message. I use it to open applications from max.

Put something like this in a message box-

;
max launchbrowser "file:///Applications/MonomeSerial.app"

Note the escape slashes on the quotes. Obviously, use a path to the file you want to launch.

Here is a patch with the message box, just to be clear

– Pasted Max Patch, click to expand. –

June 7, 2009 | 6:36 pm

Guillaume beat me to it!


June 7, 2009 | 6:45 pm

thanks for the replies

i can get it to open a pdf now like this:

;
max launchbrowser c:/quake/Atomizer_Live_Patch_2.5_Instructions.pdf

however, if i try and run a game .exe like this, it doesn’t work (i immediately get an error from the game saying it couldn’t load a certain file):

;
max launchbrowser c:/quake/fitzquake080.exe

and this message does nothing (not even an error):

;
max launchbrowser c:/quake/quakedelirium.cmd

can anybody clarify what is actually happening and why a pdf will run but not these .exe or .cmd files? and is there a simple way to get these kind of files to run, or do i need to look at java objects (if it’s the latter an example would be really helpful)?


June 7, 2009 | 7:03 pm

i’m not sure you’ll be able to launch executables this way.
the max message tells your system to open a file with the default application.

i don’t really know what’s going on in background with this message.

g


June 7, 2009 | 10:57 pm

If the launchbrowser message doesn’t work here is a java class that will launch an executable.

nice work with quake by the way!


June 7, 2009 | 11:09 pm
jan.jdo wrote on Sun, 07 June 2009 16:57
If the launchbrowser message doesn’t work here is a java class that will launch an executable.

nice work with quake by the way!

thanks will give that a go.

btw. sorry for the confusing cross posting, but did you see my post on the original thread about sending keystrokes here (i’m trying to get the quake patch into an application but i can’t get your autobot.mxj to work in a collective or application…?):

http://www.cycling74.com/forums/index.php?t=msg&th=37895&start=0&rid=6363&S=4d6474ee1c8b5e13b04aeba2b2fb24f6


June 15, 2009 | 12:13 pm
jan.jdo wrote on Sun, 07 June 2009 16:57
If the launchbrowser message doesn’t work here is a java class that will launch an executable.

nice work with quake by the way!

with this java class, what message do you send it to open a file which is in the same folder? for example it would be great if i can get this working in the quake patch, so you click a button within the patch to run the game… for this it needs to run:

quake_delirium.cmd

where that file is in the same folder as the patch application (but the whole file path cannot be specified).

can that be done with your java class?


June 15, 2009 | 8:57 pm

you could find the path to your application in max then construct a full path to the quake file and use that with the launch message. something like:

– Pasted Max Patch, click to expand. –

jan,.


June 16, 2009 | 5:36 am
genfu wrote on Sun, 07 June 2009 20:45
however, if i try and run a game .exe like this, it doesn’t work (i immediately get an error from the game saying it couldn’t load a certain file):

;
max launchbrowser c:/quake/fitzquake080.exe

and this message does nothing (not even an error):

;
max launchbrowser c:/quake/quakedelirium.cmd

can anybody clarify what is actually happening and why a pdf will run but not these .exe or .cmd files?

can it be that it has something to do with the
"helper apps" of your browser and/or system settings?

this would explain why it does not work on windows, where
propbably IE has taken control over the OS´s settings.


December 3, 2012 | 4:00 am

I’ll add some more info to this since I’ve been doing some similar work lately, needing to run .exes from inside the patch. As others have pointed out, launching exes via the launchbrowser message does not work.

I was able to work around this, using simple Visual Basic scripts to execute shell commands.

So, from Max I send a (; max launchbrowser myOpenFileScript.vbs), then the vb script opens the file. You can’t pass arguments this way, but probably fine if you’re hard-coding exe paths.

The advantage over using a Java class is that all Windows systems have Visual Basic, but some may not have Java installed. A big plus when distributing standalones.


Viewing 13 posts - 1 through 13 (of 13 total)