问题
Is there a way to hide a cmd window in Clarion 8?
I run xcopy to copy files defined in fields an application so it looks something like this:
Run('Xcopy '&Clip(Loc:Pathfrom)&' '&loc:Pathto')
i.e. Run(' C:\Temp\Temp.tps c:\Bakup\')
.
Maybe there is a cmd or Clarion command not to show the black window but only do the copying?
回答1:
No. Using the Clarion RUN()
function with a console application like xcopy.exe
, it isn't possible to hide the command line interface window using the documented options.
Example Clarion program:
PROGRAM
MAP
END
pathFrom cstring('C:\Temp\Temp.tps') !You could use STRING instead of CSTRING, but then must use CLIP(pathFrom) below
pathTo cstring('c:\Backup\')
CODE
!You will see a black cmd.exe console window open to run ththe following CLI command
Run('xcopy ' & pathFrom & ' ' & pathTo, true) !second parameter of true means to wait for the program being "run" to complete.
However, One way to workaround this is to use a non-console application to do the work, or to simply run the console app with the command line interface hidden. I have done the latter with AutoIT. Just as Clarion offers a Run()
function, so does AutoIT, but with the additional ability to hide the window.
AutoIT script (runhidden.au3 compiled as runhidden.exe):
Opt("TrayIconHide",1) ;This hides AutoIT's default systray icon from appearing
dim $command = $CmdLine[1] & ' ' & $CmdLine[2] & ' ' & $CmdLine[3] & ' ' & $CmdLine[4]
Run ( $command,"",@SW_HIDE)
Example Clarion program which uses the compiled AutoIT script above:
PROGRAM
MAP
END
pathFrom cstring('C:\Temp\Temp.tps')
pathTo cstring('c:\Backup\')
CODE
!You won't see a black cmd.exe console window opened by the following CLI command:
Run('runhidden.exe xcopy '& pathFrom & ' ' & pathTo, true)
You need not use AutoIT for the above technique, but AutoIT is free and easy to use.
回答2:
Unless there is some reason that you prefer to use the command line copy/xcopy command, why not just use Clarion's built in Copy function to copy the file?
回答3:
I understand why you don't want to use the builtin COPY command as you should need to find every single file (and possibly folder too) under that folder you want to copy. If I were you I'll use the proper tools to do it: Windows API and hide the window.
PROGRAM
SW_HIDE EQUATE(0)
SW_SHOW EQUATE(5)
MAP
MODULE('SHELL')
ShellExecute(hWnd,|
*CSTRING Operation,|
*CSTRING PathAndFileName,|
*CSTRING CommandLineParameters,|
*CSTRING DefaultDirectory,|
LONG ShowCommandCode),|
hInstance,|
PASCAL,RAW,NAME('ShellExecuteA')
END
END
LOC:OPN CSTRING(50)
LOC:NSTR CSTRING(100
LOC:CMD CSTRING(255)
LOC:DD CSTRING(255)
CODE
LOC:OPN = 'open'
LOC:NSTR = 'C:\Temp\Temp.tps c:\Bakup\'
LOC:DD = 'C:\Temp'
LOC:Cmd = 'XCOPY'
ShellExecute(0{PROP:Handle},LOC:OPN,LOC:CMD,LOC:NSTR,LOC:DD,SW_HIDE)
This code has not been tested.
回答4:
Perhaps using the CreateProcess API function with the CREATE_NO_WINDOW
flag is another way to do this?
You should be able to locate some examples in Clarion code around the place. A good starting point is the CreateProcessCaptureOutput
method of CML_System_IO_CaptureStdOutput.clw
found in the ClarionMagLibrary:
https://github.com/devroadmaps/ClarionMagLibrary/tree/master/libsrc
Tweak that as needed?
来源:https://stackoverflow.com/questions/25851041/hide-cmd-window-from-clarion