Shellexecute并等待并保持控制台窗口打开?

Shellexecute并等待并保持控制台窗口打开?

问题描述:

在Delphi 10.1中,我需要执行另一个外部控制台程序,并等待其他外部控制台程序终止。但其他外部控制台窗口在完成其工作后应保持打开状态。Shellexecute并等待并保持控制台窗口打开?

现在我用这个JCL(JEDI)功能:

ThisShellExecResult := JclShell.ShellExecAndWait(
    ThisProgram,  // Filename 
    ThisParameters, // Parameters 
    '',    // Verb (Operation) 
    ThisShowCommand, // ShowCommand (SW_SHOW or SW_HIDE) 
    ThisDirectory, // Directory 
); 

此功能以及它等待,直到外部控制台程序终止。

但我怎样才能让外部控制台程序保持其控制台窗口打开?

我经常看到提到的一个/k参数来保持控制台窗口打开。

但是它如何适应这个函数的上下文呢?

+0

'/ K'是'cmd.exe'的命令行开关。你可以使用'ShellExecute/Ex()'或'CreateProcess()'来运行'cmd.exe/K otherprogram.exe' –

正如我的问题是“但它如何适合这个功能的上下文?” (其中的参数传递给外部程序,在从问题的代码示例),这里是答案:

ThisShellExecResult := JclShell.ShellExecAndWait(
    'cmd.exe',  // Filename 
    '/K ' + JclStrings.StrQuote(ThisProgram, '"') + ' ' + ThisParameters, // Parameters 
    '',    // Verb (Operation) 
    ThisShowCommand, // ShowCommand (SW_SHOW or SW_HIDE) 
    ThisDirectory // Directory 
); 

这工作,因为我已经通过试验证实它。