how to run external program with optional switch?


i am trying to figure-out how to run a external program with switch in command line.

for instance i can run (winrar e E:\gish.rar E:/tt) to extract the gish named archive in tt folder through windows command can i do the same through maxscript?

i guess "DOSCommand","shelllaunch" or "HiddenDOSCommand" might help but all i can do is open the gish file by running (hiddendoscommand "E:\gish.rar")

please anybody help me out.

ps.the syntax for winrar is (WinRAR <command> -<switch1> -<switchN> <archive> <files...> <@listfiles...> <path_to_extract\> )



Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
Anubis's picture

just supply your full string command

try this:
HiddenDOSCommand @"WinRAR E 'E:\gish.rar' 'E:\tt'" startpath:"c:\\"

if the single quote-mark (') give error then s'd reformat the string, like:
HiddenDOSCommand "WinRAR E \"E:\\gish.rar\" \"E:\\tt\\"" startpath:"c:\\"

well, in this case you can go even w/o quotes...
HiddenDOSCommand @"WinRAR E E:\gish.rar E:\tt" startpath:"c:\\"
...because the path to the file end output path has not space (" ") char, but if they have (like "C:\Prgram Files") then s'd enclose this paths within quotes, but maybe you know this as this is commont for all command line calls.

my recent MAXScripts RSS (archive here)

zahidhasan's picture

thanks for the quick

thanks for the quick response. but still i cant make it work. all i get is "true" in listner. do you think it might be winrar that is the problem?

and maxscript is my first coding experience.even didnt run a program from commandline before.:-)so please be patient.

Anubis's picture

aha, ok

Well, make this test then.
[.] Put some valid rar file in "C:\" and name it "test.rar"
[.] Create a text file in "C:\" and name it "unrar.bat" (the file extension bat is important)
[.] Open unrar.bat in Notepad
[.] Copy, paste and save this command to it:

WinRAR E C:\test.rar C:\

[.] Run the .BAT file

Now the analyse.

If that not extract the "test.rar" then the console window s'd print some error message. The PAUSE is inside just to keep the console open, to can read whats wrong.

So, if there some message like 'WinRAR' is not recognizable command, then should use a full path to your WinRAR, i.e. if for example it installed in C:\Program Files (x86)\WinRAR\, then your dos command become:

"C:\Program Files (x86)\WinRAR\WinRAR.exe" E C:\test.rar C:\

Hope this help ;)

my recent MAXScripts RSS (archive here)

zahidhasan's picture

it is working nicely.first

it is working nicely.
first there was the error about non recognizable winrar. adding the full path solves this.

in the meantime i managed making a batch file from withing max by format command and running it by doscommand of maxscript .which works.but a bit silly. :-)

start winrar e E:\gish.rar E:/tt

thanks again. i gonna put the full path in your 1st post? i mean into this

HiddenDOSCommand @"WinRAR E 'E:\gish.rar' 'E:\tt'" startpath:"c:\\"

Anubis's picture

s'd use \ to format the string

HiddenDOSCommand " \"C:\\Program Files (x86)\\WinRAR\\WinRAR.exe\" E \"E:\\gish.rar\" \"E:\\tt\" " startpath:"c:\\"

then you put quotes (") inside string, formating them with backslash (\) made them compatible, this way the engine know that this sign is not mark the end of the string.

for example this command conteins quotes...
Box name:"foo"

so if by some reason s'd be inserted in a string...
execute(" Box name:\"foo\" ")

...then above will be valid.

note too, that single backslash (\) in the file paths also replaced with \\.

In the Mxs reference search for String Literals to see all valid escape sequences ;)

my recent MAXScripts RSS (archive here)

zahidhasan's picture

everything is magically

everything is magically solved.
so putting double quotes resulting in a immature escape.
thanks for the i have a good idea about the "\"".

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.