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
"RunWait": complex concatenating
"RunWait": complex concatenating
Peter (AHK Beginner) / Win 10 x64, AHK Version v1.1.33
Re: "RunWait": complex concatenating
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.
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
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
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
Peter (AHK Beginner) / Win 10 x64, AHK Version v1.1.33
Re: "RunWait": complex concatenating
There are many ways to solve this.
1) the manual show some ideas for Run
If you must run your AHK-program as administrator, this is a good tip
Now to your desire
Maybe this example can help you in some way?
I would try something similar (untested) or the example above or... .:
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""
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%
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
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
Thanks @Albireo
I will test it tomorrow.
Peter2
I will test it tomorrow.
Peter2
Peter (AHK Beginner) / Win 10 x64, AHK Version v1.1.33
Re: "RunWait": complex concatenating
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%"
But nevertheless - although the variables are used: never forget to quote them (for existing blanks and that stuff)
RunWait %ComSpec% /c "%ProgName%" "%Config%" >> "%ResultFile%"
Last edited by Peter2 on 28 May 2019, 05:39, edited 1 time in total.
Peter (AHK Beginner) / Win 10 x64, AHK Version v1.1.33
Re: "RunWait": complex concatenating
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
Example-2 defined color,position and size , run all command at DOS-start
( 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
aa=@echo 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
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