RunProgramm cmd.exe Example
RunProgramm cmd.exe Example
From within a Windows program, I want to execute a command line operation using RunProgram: for example, "Cmd.exe /C copy a.txt b.txt."
Does anyone have an example syntax for this? Thanks.
Does anyone have an example syntax for this? Thanks.
Re: RunProgramm cmd.exe Example
it mostly depends on what you are planning to do...
In this case you posted i would use CopyFile instead of opening a console
RunProgram("cmd.exe", Parameter$, WorkDir$) is the minimum... the example in the docs are ok with it.
ups....
In this case you posted i would use CopyFile instead of opening a console

RunProgram("cmd.exe", Parameter$, WorkDir$) is the minimum... the example in the docs are ok with it.
ups....
Code: Select all
RunProgram("cmd.exe", "copy C:\text.txt D:\text.txt", "")
Re: RunProgramm cmd.exe Example
Small oversightBisonte wrote: Fri Apr 25, 2025 12:31 pm it mostly depends on what you are planning to do...
In this case you posted i would use CopyFile instead of opening a console
RunProgram("cmd.exe", Parameter$, WorkDir$) is the minimum... the example in the docs are ok with it.
ups....
Code: Select all
RunProgram("cmd.exe", "copy C:\text.txt D:\text.txt", "")

Code: Select all
RunProgram("cmd.exe", "/c copy C:\text.txt D:\text.txt", "")
/k to do command and keep shell open
and best
Code: Select all
RunProgram(GetEnvironmentVariable("ComSpec"), "/c ...
Re: RunProgramm cmd.exe Example
Code: Select all
; needs admin mode
RunProgram("cmd.exe","/C copy "+~"\""+"C:\my text.txt"+~"\" \""+"C:\my text2.txt"+~"\"","",#PB_Program_Wait|#PB_Program_Hide)
Re: RunProgramm cmd.exe Example
With ~ " " you can simplify (A single tild is enough)Piero wrote: Fri Apr 25, 2025 4:22 pmCode: Select all
; needs admin mode RunProgram("cmd.exe","/C copy "+~"\""+"C:\my text.txt"+~"\" \""+"C:\my text2.txt"+~"\"","",#PB_Program_Wait|#PB_Program_Hide)
Code: Select all
Debug "/C copy "+~"\""+"C:\my text.txt"+~"\" \""+"C:\my text2.txt"+~"\""
Debug ~"/C copy \"C:\\my text.txt\" \"C:\\my text2.txt\""
Code: Select all
/C copy "C:\my text.txt" "C:\my text2.txt"
/C copy "C:\my text.txt" "C:\my text2.txt"

Re: RunProgramm cmd.exe Example
I believe you also could call the command directly like this:
(I dont know about windows though, but i'm pretty sure i've called terminal commands like that with Linux.)
Code: Select all
RunProgram("copy", "C:\text.txt D:\text.txt", "")
Re: RunProgramm cmd.exe Example
If parameters contains spaces, you need to use quotesFips wrote: Fri Apr 25, 2025 6:44 pm I believe you also could call the command directly like this:(I dont know about windows though, but i'm pretty sure i've called terminal commands like that with Linux.)Code: Select all
RunProgram("copy", "C:\text.txt D:\text.txt", "")
In Linux (all unix), the official 'copy' command (cp) is a standalone program (/usr/bin/cp) so you can call it as first with run program.
In Windows, 'copy' is an internal command of the shell (defaut: cmd.exe for NT systems (Win NT, 8, 10, 11) or command.com in Windows 9.x and DOS) Shell contain commands like, copy, del, ... but not all (i.e xcopy is a standalone program (xcopy.exe))
Type cmd /? to show all

Re: RunProgramm cmd.exe Example
Lot of helpful Information! Thank you!
Re: RunProgramm cmd.exe Example
The answers always depend on the particular application.
If you also want to run the application on other computers, I recommend the following option.
You avoid unexpected reactions.
Code: Select all
/D Disable execution of AutoRun commands from registry
Code: Select all
cmd.exe /D/C copy ....
Maybe it is a good idea to read the help of cmd.exe
Code: Select all
cmd.exe /?
Just because it worked doesn't mean it works.
PureBasic 6.04 (x86) and <latest stable version and current alpha/beta> (x64) on Windows 11 Home. Now started with Linux (VM: Ubuntu 22.04).
PureBasic 6.04 (x86) and <latest stable version and current alpha/beta> (x64) on Windows 11 Home. Now started with Linux (VM: Ubuntu 22.04).
Re: RunProgramm cmd.exe Example
Marc56us wrote: Fri Apr 25, 2025 5:09 pm With ~ " " you can simplify (A single tild is enough)Code: Select all
Debug "/C copy "+~"\""+"C:\my text.txt"+~"\" \""+"C:\my text2.txt"+~"\"" Debug ~"/C copy \"C:\\my text.txt\" \"C:\\my text2.txt\""
![]()
Code: Select all
; needs admin mode
f.s = "C:\my text.txt" ; %~dpn means Disk Path Name
c.s = ~"( FOR %I IN (\"" + f + ~"\") DO copy %I \"%~dpnI 2%~xI\" && echo Done! ) || echo Error!!!"
RunProgram("cmd.exe","/D/K "+c,"") ; copy "C:\my text.txt" "C:\my text 2.txt"
