integrating windows commands

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
marypoppins_1
Posts: 95
Joined: 28 Oct 2020, 02:58

integrating windows commands

28 Mar 2024, 05:33

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 ??
garry
Posts: 3770
Joined: 22 Dec 2013, 12:50

Re: integrating windows commands

28 Mar 2024, 06:44

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
Last edited by garry on 28 Mar 2024, 08:09, edited 2 times in total.
marypoppins_1
Posts: 95
Joined: 28 Oct 2020, 02:58

Re: integrating windows commands

28 Mar 2024, 07:40

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?
garry
Posts: 3770
Joined: 22 Dec 2013, 12:50

Re: integrating windows commands

28 Mar 2024, 07:57

%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
marypoppins_1
Posts: 95
Joined: 28 Oct 2020, 02:58

Re: integrating windows commands

28 Mar 2024, 08:36

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
RussF
Posts: 1269
Joined: 05 Aug 2021, 06:36

Re: integrating windows commands

28 Mar 2024, 08:51

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
Last edited by RussF on 28 Mar 2024, 10:10, edited 1 time in total.
garry
Posts: 3770
Joined: 22 Dec 2013, 12:50

Re: integrating windows commands

28 Mar 2024, 09:25

@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
--------------------------------------------
*/

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: Google [Bot], Rohwedder and 247 guests