| View previous topic :: View next topic |
| Author |
Message |
Stanley Krute
Joined: 30 Jul 2005 Posts: 38
|
Posted: Thu Nov 19, 2009 8:36 am Post subject: executing a complex command string from a script |
|
|
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 |
|
 |
Gast w/o Nick Guest
|
Posted: Thu Nov 19, 2009 11:48 am Post subject: |
|
|
| 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
|
Posted: Thu Nov 19, 2009 5:13 pm Post subject: |
|
|
| 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 |
|
 |
rtcvb32
Joined: 17 Feb 2008 Posts: 125
|
Posted: Thu Nov 19, 2009 8:24 pm Post subject: |
|
|
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 |
|
 |
Stanley Krute
Joined: 30 Jul 2005 Posts: 38
|
Posted: Fri Nov 20, 2009 12:51 am Post subject: |
|
|
| 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 |
|
 |
a_h_k
Joined: 02 Feb 2008 Posts: 344
|
Posted: Mon Nov 30, 2009 8:30 am Post subject: Re: executing a complex command string from a script |
|
|
| 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 |
|
 |
hugov
Joined: 27 May 2007 Posts: 2181
|
Posted: Mon Nov 30, 2009 8:43 am Post subject: |
|
|
@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 |
|
 |
a_h_k
Joined: 02 Feb 2008 Posts: 344
|
Posted: Mon Nov 30, 2009 9:18 am Post subject: |
|
|
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 |
|
 |
|