AutoHotkey Community

It is currently May 26th, 2012, 8:49 pm

All times are UTC [ DST ]




Post new topic Reply to topic  [ 4 posts ] 
Author Message
PostPosted: June 13th, 2009, 1:11 am 
Offline

Joined: March 8th, 2008, 11:36 am
Posts: 64
Location: Santa Barbara
Why does the AutoHotkey Run command have this design goal:
  • User can launch a document name containing spaces without having to enclose it in double quotes.
This design decision is preventing users from passing parameters to script files. e.g. you can't do:
Code:
Run, MyScript.vbs param1 param2 param3
  • It's easy to enclose a filename containing spaces in double quotes
  • The DOS command prompt requires double quotes around a file name containing spaces
  • This goal prevents the AutoHotkey Run command from working like a DOS line mode command. Specifically, users can not pass parameters to scripts.
I know there are ugly workarounds, such as using %comspec%, which causes a DOS window to temporarily flash onto the screen.


Report this post
Top
 Profile  
Reply with quote  
PostPosted: June 13th, 2009, 3:05 am 
Offline

Joined: April 18th, 2008, 7:57 am
Posts: 1390
Location: The Interwebs
deleyd wrote:
I know there are ugly workarounds, such as using %comspec%, which causes a DOS window to temporarily flash onto the screen.

You can run the window as hidden by specifying that in the Run options.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: June 13th, 2009, 8:44 am 
Offline

Joined: October 17th, 2006, 4:15 pm
Posts: 7502
Location: Australia
Perhaps Run should behave like CreateProcess:
Quote:
The lpApplicationName parameter can be NULL. In that case, the module name must be the first white space–delimited token in the lpCommandLine string. If you are using a long file name that contains a space, use quoted strings to indicate where the file name ends and the arguments begin; otherwise, the file name is ambiguous. For example, consider the string "c:\program files\sub dir\program name". This string can be interpreted in a number of ways. The system tries to interpret the possibilities in the following order:
    c:\program.exe files\sub dir\program name
    c:\program files\sub.exe dir\program name
    c:\program files\sub dir\program.exe name
    c:\program files\sub dir\program name.exe
Source: MSDN: CreateProcess Function
I suppose it would just need to test each space-delimited substring as is before appending ".exe".

Comments in the AutoHotkey source code say (about CreateProcess, which is used by Run for executable files):
Code:
         // MSDN: "If [lpCurrentDirectory] is NULL, the new process is created with the same
         // current drive and directory as the calling process." (i.e. since caller may have
         // specified a NULL aWorkingDir).  Also, we pass NULL in for the first param so that
         // it will behave the following way (hopefully under all OSes):
"the first white-space – delimited
         // token of the command line specifies the module name. If you are using a long file name that
         // contains a space, use quoted strings to indicate where the file name ends and the arguments
         // begin (see the explanation for the lpApplicationName parameter). If the file name does not
         // contain an extension, .exe is appended. Therefore, if the file name extension is .com,
         // this parameter must include the .com extension. If the file name ends in a period (.) with
         // no extension, or
if the file name contains a path, .exe is not appended. If the file name does
         // not contain a directory path, the system searches for the executable file in the following
         // sequence...".

I suppose the red text is no longer accurate for "current" versions of Windows.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: June 21st, 2009, 9:34 pm 
Code:
Run, cscript.exe //nologo "MyScript.vbs" "something" "somethingelse" "param3", , Hide

;or

myscript = MyScript.vbs
param1 = something
param2 = somethingelse

Run, cscript.exe //nologo "%myscript%" "%param1%" "%param2%" "param3", , Hide


Report this post
Top
  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 4 posts ] 

All times are UTC [ DST ]


Who is online

Users browsing this forum: No registered users and 10 guests


You can post new topics in this forum
You can reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Powered by phpBB® Forum Software © phpBB Group