Page 1 of 1

integrating windows commands

Posted: 28 Mar 2024, 05:33
by marypoppins_1
hello. hhow would i integrate windows commands into ahk.
precisely

Code: Select all

Run, xcopy Calculator.ahk %A_MyDocuments%\mycodes\ /S
so this is a windows copy termimal command. (usage: xcopy source destination [parameters]) how can i integrate ahk variables into the source / destination? is it "AHK" syntax ??

Re: integrating windows commands

Posted: 28 Mar 2024, 06:44
by garry
short example, see also filecopy , robocopy etc

Code: Select all

source:=a_desktop . "\calculator.ahk"
dest  :="D:\TEST" 
runwait,%comspec% /k xcopy "%source%" "%dest%"
try,run,%dest%
return
copy DESKTOP to D:\TEST\DESKTOP

Code: Select all

source:=a_desktop
dest  :="D:\TEST\DESKTOP"
;ifnotexist,%dest%    ;- < not needed see parameter /I 
;  filecreatedir,%dest%
runwait,%comspec% /k xcopy "%source%" "%dest%" /s /e /I
try,run,%dest%
return

Re: integrating windows commands

Posted: 28 Mar 2024, 07:40
by marypoppins_1
it worked. can you please explain what is comspec and /k?? also can i write it my way? (without comspec and /k) do i just put the string in the variable and call it using "%myvar%" in the run cmd?

Re: integrating windows commands

Posted: 28 Mar 2024, 07:57
by garry
%comspec% is cmd , /k > keep DOS open , /c > close DOS when finished

run myvar :

Code: Select all

myvar=xcopy %a_desktop%\calculator.ahk D:\TEST
run,%myvar%
return

open DOS

Code: Select all

run,%comspec% /k
return
an example , run hidden

Code: Select all

source:=a_desktop . "\calculator.ahk"
dest  :="D:\TEST" 
ifnotexist,%dest%
  filecreatedir,%dest%
runwait,%comspec% /c xcopy "%source%" "%dest%" /Y | clip,,hide  ;- hidden and overwrite dest
msgbox,%clipboard%   ;- < see DOS command
try,run,%dest%
return
copy DESKTOP to D:\TEST\DESKTOP2 ( parameter /I creates new dest-folder if not exists , /s = subfolder /e= empty folder , %comspec% /k = let DOS open to see what happens )

Code: Select all

source:=a_desktop
dest  :="D:\TEST\DESKTOP2"
runwait,%comspec% /k xcopy "%source%" "%dest%" /s /e /I
try,run,%dest%
return

Re: integrating windows commands

Posted: 28 Mar 2024, 08:36
by marypoppins_1
so the 3rd and fourth are kind of similar, one is hidden the other is not but they both used comspec. the first is using pure xcopy (i prefer this approach). btw you can add the same parameters that you added in the fourth / 3rd into the first. (xcopy documentation). i just couldn't find documentation for comspec if you may, please.
THE reason i'm using xcopy over the ahk filecopy is due to the available features

Re: integrating windows commands

Posted: 28 Mar 2024, 08:51
by RussF
Comspec is nothing more than the path to the Windows Cmd.exe that is specific to your system. To see the command line options available when invoking Cmd.exe, you can visit this Microsoft website or this site for more information.

Russ

Re: integrating windows commands

Posted: 28 Mar 2024, 09:24
by marypoppins_1
great, thank you

Re: integrating windows commands

Posted: 28 Mar 2024, 09:25
by garry
@RussF thank you
can also open cmd with WIN+R ,cmd ,ENTER , then see DOS window, type CMD /? > see all parameters
also help for xcopy > XCOPY /?
( /? can be used for all DOS commands to get help )
with ahk open DOS with > run,%comspec% /k

I get a NEW DOS window after new installing windows , run wt.exe , use settings to get the OLD DOS window back ....

Code: Select all

try,run,C:\Program Files\WindowsApps\Microsoft.WindowsTerminal_1.19.10573.0_x64__8wekyb3d8bbwe\wt.exe
/*
Windows Power Shell , Settings in wt.exe
-------------------------------------------
Standard Profile :
- as Windows Power Shell
- as DOS
- as Azure Cloud Shell
-------------------------------------------
standard terminal application :
-Windows decides
-Windows console host  >> DOS old   I used this    >> ahk_class ConsoleWindowClass    
-Windows Terminal      >> DOS new , like wt.exe  >>  ahk_class CASCADIA_HOSTING_WINDOW_CLASS
--------------------------------------------
*/