AutoHotkey Community

It is currently May 27th, 2012, 12:16 am

All times are UTC [ DST ]




Post new topic Reply to topic  [ 8 posts ] 
Author Message
PostPosted: November 19th, 2009, 9:36 am 
Offline

Joined: July 30th, 2005, 3:49 pm
Posts: 42
Hi

I have a complex run command. The program is named foogoo. The parameter string is long and twisted. Here's the full thing:

Code:
foogoo C: "L:\aaa documents by DoxMonger\Cee on Stan-Tower\documents starting 2009-11-17\$DISK Treasure $YEAR-$MONTH-$DAY Funny.MBA" -funny"L:\aaa documents by DoxMonger\Cee on Stan-Tower\documents starting 2009-11-17\C Treasure 2009-11-17 Wacky.PhD" -why -not -be -rich > "L:\aaa documents by DoxMonger\Cee on Stan-Tower\documents starting 2009-11-17\C Treasure 2009-11-19 Spungy.iou"


What is the best way to execute that from an AHK script ?

I had problems with the param string with the Run command. I tried escape chars and multiple double-quotes and this and that, but got nowhere. So what I'm doing now -- it's a bit oogly, but it works -- is opening a comspec window, and sending the command string into it, then sending an Enter key. Like this:

Code:
run %comspec% /k,,,cmdWndwPID
Sleep 1000
send %gdBackupCmdStr%
send {Enter}
WinMinimize, ahk_pid %cmdWndwPID%.


I'm thinking there's got to be a way to do this that's cleaner and more reliable. But maybe not. Hey, I'm a noob !!! Any thoughts ??

thx

-- stan


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: November 19th, 2009, 12:48 pm 
Quote:
I'm thinking there's got to be a way to do this that's cleaner and more reliable. But maybe not. Hey, I'm a noob !!! Any thoughts ??


One thing I would do is use
"ControlSend / ControlSendRaw" instead
of Send (see AHK help for syntax)

This will allow you to send into a window in the background, so your
sent keys will always arrive.

Another more reliable solution is to create a temporary batch file in the %A_Temp% directory and run that.



[/code]


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: November 19th, 2009, 6:13 pm 
Offline

Joined: July 30th, 2005, 3:49 pm
Posts: 42
Gast w/o Nick wrote:
One thing I would do is use
"ControlSend / ControlSendRaw" instead
of Send (see AHK help for syntax)

This will allow you to send into a window in the background, so your
sent keys will always arrive.


Thanks Gast. Here's the new code, based on that:

Code:
run %comspec% /k,,,cmdWndwPID
Sleep 3000
WinMinimize, ahk_pid %cmdWndwPID%
ControlSend,, %gdBackupCmdStr%, ahk_pid %cmdWndwPID%
ControlSend,, {Enter}, ahk_pid %cmdWndwPID%


Nice bonus thing there beyond transmission reliablity is that I can minimize the compsec window rt. away, but the send keys still get there just fine.

Thanks muchos ....

-- stan


Last edited by Stanley Krute on November 20th, 2009, 4:50 am, edited 1 time in total.

Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: November 19th, 2009, 9:24 pm 
Offline

Joined: February 17th, 2008, 7:09 am
Posts: 536
Another alternative, if you need you can make a .bat file and then just run it.

Code:
if (! FileExist("file.bat")) {
fileappend,
(
echo Hey i ran! See me Run!
cmd
), file.bat
sleep 1000
}

Run, file.bat


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: November 20th, 2009, 1:51 am 
Offline

Joined: July 30th, 2005, 3:49 pm
Posts: 42
rtcvb32 wrote:
Another alternative, if you need you can make a .bat file and then just run it.

Code:
if (! FileExist("file.bat")) {
fileappend,
(
echo Hey i ran! See me Run!
cmd
), file.bat
sleep 1000
}

Run, file.bat


Ah. Very cool and simple. Thanks rtcvb32.

It WOULD be nice to just be able to call the Run command, with some way to get that long param string chewed on correctly, so as to not have the extra CMD line window that comes from all of these workarounds. But these are just fine for now.

When I get a bit of time, I'd like to experiment with using DllCall to invoke the Win32 CreateProcess function to achieve my goal more directly. Will report back on that when/if.

== stan


Report this post
Top
 Profile  
Reply with quote  
PostPosted: November 30th, 2009, 9:30 am 
Offline

Joined: February 2nd, 2008, 4:35 am
Posts: 643
Code:
foogoo C: "L:\aaa documents by DoxMonger\Cee on Stan-Tower\documents starting 2009-11-17\$DISK Treasure $YEAR-$MONTH-$DAY Funny.MBA" -funny "L:\aaa documents by DoxMonger\Cee on Stan-Tower\documents starting 2009-11-17\C Treasure 2009-11-17 Wacky.PhD" -why -not -be -rich > "L:\aaa documents by DoxMonger\Cee on Stan-Tower\documents starting 2009-11-17\C Treasure 2009-11-19 Spungy.iou"
y" --> y " (space needed)
$DISK = eg (what)?
$YEAR-$MONTH-$DAY = eg 09-11-30 ?
> = what?


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: November 30th, 2009, 9:43 am 
Offline

Joined: May 27th, 2007, 9:41 am
Posts: 4999
@AutoHotkey: these are probably environment variables available in dos (batch files) and the > is used to redirect output to a file (e.g. fileappend in autohotkey).

_________________
AHK FAQ
TF : Text files & strings lib, TF Forum


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: November 30th, 2009, 10:18 am 
Offline

Joined: February 2nd, 2008, 4:35 am
Posts: 643
For 1st part
Code:
EnvGet, DISK, DISK
Run, foogoo.exe C: "L:\aaa documents by DoxMonger\Cee on Stan-Tower\documents starting 2009-11-17\%DISK% Treasure %A_Year%-%A_Mon%-%A_MDay% Funny.MBA" -funny "L:\aaa documents by DoxMonger\Cee on Stan-Tower\documents starting 2009-11-17\C Treasure 2009-11-17 Wacky.PhD" -why -not -be -rich

Not sure about how to redirect output though
Code:
;(code to redirect above output to below file)
"L:\aaa documents by DoxMonger\Cee on Stan-Tower\documents starting 2009-11-17\C Treasure 2009-11-19 Spungy.iou"


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

All times are UTC [ DST ]


Who is online

Users browsing this forum: Apollo, Bing [Bot], Leef_me, Pulover, rjgatito, XstatyK and 20 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