Page 1 of 1

"RunWait": complex concatenating

Posted: 27 May 2019, 12:42
by Peter2
have a command call, at the moment called via a BAT / CMD file. It starts an EXE with a (long) parameter and writes the output to a log-file (>> command).

It looks like this
"C:\Program Files\Autodesk\AutoCAD 2018\Map\bin\IMBatch.exe" ConfigFile= x:\my test\data\1-klick_wartung_vlwa.xml >> results_vlwa.log

Now I want to
- replace the BAT with a "Runas" from AHK (The GUI and all that stuff is already done)
- use a part of the string as variable because of multiple usage of the Runas

So I want to do this (not working fake code):

myvalue = vlwa
RunWait, "C:\Program Files\Autodesk\AutoCAD 2018\Map\bin\IMBatch.exe" ConfigFile= x:\my test\data\1-klick_wartung_%myvalue%.xml >> %A_ScriptDir%\results_%myvalue%.log
myvalue = foo
runwait, ....


But I have problems to get the right string - due to the collection of (multiple?) quotes, blanks, = and > and AHK-variables.
(Question for advanced: Is it a good idea to keep the output with the CMD commands ">>"? Or is there an AHK output-handling?)

I'm happy if someone can help me with that.

Peter

Re: "RunWait": complex concatenating

Posted: 27 May 2019, 13:16
by Albireo
Can you start the program directly from windows or should you start the program with cmd promt?
Do you want to start the file directly from AHK? or is it enough that you run the bat file?
A good way to handle this is to create variables, (Check that these look real with MsgBox) and then use them.

Re: "RunWait": complex concatenating

Posted: 27 May 2019, 13:55
by Peter2
This EXE has to be started from command-line, because I don't know another way to pass the parameters.

My first way was to create BAT-files, but this will be unhandy to maintain and to use: a lot of batches where only a few letters are different. This is why I made a GUI which checkboxes where I can select comfortably a lot of options and run them step-by-step with RunWait

Re: "RunWait": complex concatenating

Posted: 27 May 2019, 15:34
by Albireo
There are many ways to solve this.
1) the manual show some ideas for Run

Code: Select all

Run %ComSpec% /c ""C:\My Utility.exe" "param 1" "second param" >"C:\My File.txt""
If you must run your AHK-program as administrator, this is a good tip

Code: Select all

full_command_line := DllCall("GetCommandLine", "str")

if not (A_IsAdmin or RegExMatch(full_command_line, " /restart(?!\S)"))
{
    try
    {
        if A_IsCompiled
            Run *RunAs "%A_ScriptFullPath%" /restart
        else
            Run *RunAs "%A_AhkPath%" /restart "%A_ScriptFullPath%"
    }
    ExitApp
}

MsgBox A_IsAdmin: %A_IsAdmin%`nCommand line: %full_command_line%
Now to your desire
Maybe this example can help you in some way?

Code: Select all

aa:="echo msgbox hello world>%temp%\tmp.ahk|start %temp%\tmp.ahk"
Run,%comspec% /k, , , pid2
WinWait, ahk_pid %pid2%
ControlSend, ,cd\`n%aa%`n, ahk_pid %pid2%
return
I would try something similar (untested) or the example above or... .:

Code: Select all

myvalue = vlwa
ProgName := "C:\Program Files\Autodesk\AutoCAD 2018\Map\bin\IMBatch.exe"
Config := "ConfigFile= x:\my test\data\1-klick_wartung_" myvalue ".xml"
ResultFile = %A_ScriptDir%\results_%myvalue%.log 
RunWait %ComSpec% /c %ProgName% %Config% ">" %ResultFile%

Re: "RunWait": complex concatenating

Posted: 27 May 2019, 15:48
by Peter2
Thanks @Albireo
I will test it tomorrow.

Peter2

Re: "RunWait": complex concatenating

Posted: 28 May 2019, 03:23
by Peter2
Solved, thanks.

But nevertheless - although the variables are used: never forget to quote them (for existing blanks and that stuff)

RunWait %ComSpec% /c "%ProgName%" "%Config%" >> "%ResultFile%"

Re: "RunWait": complex concatenating

Posted: 28 May 2019, 05:04
by garry
thank you for the examples
( if I sent to DOS needed the command e.g. 'SetKeyDelay,50,50' to make send slower )
also 2 examples , send2DOS

Example-1 copy clipboard

Code: Select all

;- Example-1
#warn
setworkingdir,%a_scriptdir%
transform,s,chr,13
f1=%a_temp%\msgbox.ahk
[email protected] off%s%cd\%s%echo msgbox`,hello world >%f1%%s%start %f1%%s%
Run,%comspec% /k, , , pid2
WinWait, ahk_pid %pid2%
clipboard=%aa%
clipwait,1
ControlSend, ,^v, ahk_pid %pid2%
clipboard=
run,%a_temp%
return
Example-2 defined color,position and size , run all command at DOS-start

Code: Select all

#warn
setworkingdir,%a_scriptdir%
wa:=a_screenwidth
ha:=a_screenheight
W :=(wa*50)/100    ;- width
H :=(ha*92)/100    ;- height

f1=%a_temp%\msgbox.ahk
e4x=
(Ltrim join&
@echo off
echo date=
date /t
echo time=
time /t
ver
echo msgbox,hello world >%f1%
start %f1%
)
title2=DOS_TEST
run, %comspec% /T:0A /k "title %title2%&mode con lines=4000 cols=120&%e4x%,,,pid2
WinWait, ahk_pid %pid2%
WinMove, ahk_pid %pid2%, ,1,1,%w%,%h%       ;- move DOS to the right position
run,%a_temp%
e4x=
return