如果在调试控制台程序时运行后不会自动关闭(100分)

教父

Unregistered / Unconfirmed
GUEST, unregistred user!
在VC中调试时,一个控制台程序运行完后窗口不会自动关闭,因此可以清楚地看到它的
输出,但是BCB会自动关闭那个窗口,很是讨厌,就算用了getch()也不能完全解决问题,
因为那样不能看到类的析构函数的输出,请问有什么办法?
而且就算不需要看析构函数的输出也还是有一个讨厌的地方,为了用一个getch(),你必
须include <conio>,请问有没有办法用iostream的函数实现getch()的功能?
 
向Borland提意见。
 
设置命令行,菜单 run/parameters/
host application:
如果是nt/2000,那么设置为 c:/winnt/system32/cmd.exe
如果是win9x,那么设置为 command.com
parameters:
设置为: /k 你的程序
注意必须有“/k”
 
to Pipi.:我试了,还是不行啊
 
我在jbuilder中调试程序时通常加入以下的代码,bcb中应该是可以类似实现的。
try{
temps=System.in.read();
}catch(Exception ex){}
让程序等待输入,控制台窗口自然就不会关闭了。
 
在最后加上一句
readln
 
可以这样:在程序后面加上一句 Sleep(3000);
让程序停留3秒,时间可以自己定.
 
我听别人说的,用memo跑控制台程序。
delphi的。
procedure TForm1.Button1Click(Sender: TObject);
procedure RunDosInMemo(DosApp:String;AMemo:TMemo);
const
ReadBuffer = 2400;
var
Security : TSecurityAttributes;
ReadPipe,WritePipe : THandle;
start : TStartUpInfo;
ProcessInfo : TProcessInformation;
Buffer : Pchar;
BytesRead : DWord;
Apprunning : DWord;
begin
With Securitydo
begin
nlength := SizeOf(TSecurityAttributes);
binherithandle := true;
lpsecuritydescriptor := nil;
end;
if Createpipe (ReadPipe, WritePipe,
@Security, 0) then
begin
Buffer := AllocMem(ReadBuffer + 1);
FillChar(Start,Sizeof(Start),#0);
start.cb := SizeOf(start);
start.hStdOutput := WritePipe;
start.hStdInput := ReadPipe;
start.dwFlags := STARTF_USESTDHANDLES +
STARTF_USESHOWWINDOW;
start.wShowWindow := SW_HIDE;
if CreateProcess(nil,
PChar(DosApp),
@Security,
@Security,
true,
NORMAL_PRIORITY_CLASS,
nil,
nil,
start,
ProcessInfo)
then
begin
repeat
Apprunning := WaitForSingleObject
(ProcessInfo.hProcess,100);
Application.ProcessMessages;
until (Apprunning <> WAIT_TIMEOUT);
Repeat
BytesRead := 0;
ReadFile(ReadPipe,Buffer[0],
ReadBuffer,BytesRead,nil);
Buffer[BytesRead]:= #0;
OemToAnsi(Buffer,Buffer);
AMemo.Text := AMemo.text + String(Buffer);
until (BytesRead < ReadBuffer);
end;
FreeMem(Buffer);
CloseHandle(ProcessInfo.hProcess);
CloseHandle(ProcessInfo.hThread);
CloseHandle(ReadPipe);
CloseHandle(WritePipe);
end;
end;

begin
{button 1 code}
RunDosInMemo('ping 10.43.0.1',Memo1);
end;
 
多人接受答案了。
 

Similar threads

顶部