AutoHotkey Homepage AutoHotkey Community
Let's help each other out
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

executing a complex command string from a script

 
Post new topic   Reply to topic    AutoHotkey Community Forum Index -> Ask for Help
View previous topic :: View next topic  
Author Message
Stanley Krute



Joined: 30 Jul 2005
Posts: 38

PostPosted: Thu Nov 19, 2009 8:36 am    Post subject: executing a complex command string from a script Reply with quote

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
Back to top
View user's profile Send private message Visit poster's website
Gast w/o Nick
Guest





PostPosted: Thu Nov 19, 2009 11:48 am    Post subject: Reply with quote

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]
Back to top
Stanley Krute



Joined: 30 Jul 2005
Posts: 38

PostPosted: Thu Nov 19, 2009 5:13 pm    Post subject: Reply with quote

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 Fri Nov 20, 2009 3:50 am; edited 1 time in total
Back to top
View user's profile Send private message Visit poster's website
rtcvb32



Joined: 17 Feb 2008
Posts: 125

PostPosted: Thu Nov 19, 2009 8:24 pm    Post subject: Reply with quote

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
Back to top
View user's profile Send private message Yahoo Messenger
Stanley Krute



Joined: 30 Jul 2005
Posts: 38

PostPosted: Fri Nov 20, 2009 12:51 am    Post subject: Reply with quote

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
Back to top
View user's profile Send private message Visit poster's website
a_h_k



Joined: 02 Feb 2008
Posts: 344

PostPosted: Mon Nov 30, 2009 8:30 am    Post subject: Re: executing a complex command string from a script Reply with quote

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?
Back to top
View user's profile Send private message
hugov



Joined: 27 May 2007
Posts: 2181

PostPosted: Mon Nov 30, 2009 8:43 am    Post subject: Reply with quote

@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).
_________________
Tut 4 Newbies
TF : Text file & string lib, TF Forum
Back to top
View user's profile Send private message Visit poster's website
a_h_k



Joined: 02 Feb 2008
Posts: 344

PostPosted: Mon Nov 30, 2009 9:18 am    Post subject: Reply with quote

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"
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    AutoHotkey Community Forum Index -> Ask for Help All times are GMT
Page 1 of 1

 
Jump to:  
You can post new topics in this forum
You can reply to topics in this forum


Powered by phpBB © 2001, 2005 phpBB Group