![]() |
Re: cmd fenster
scheiße :oops: :oops:
wenn meine batchdatei ausgeführt wird geht immer noch das cmd fenster auf hier schaut mal rein: unit Unit1; interface uses Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls,ShellAPI; type TForm1 = class(TForm) MemoOutput: TMemo; Button1: TButton; procedure FormCreate(Sender: TObject); procedure FormClose(Sender: TObject; var Action: TCloseAction); procedure Button1Click(Sender: TObject); private fInputPipeRead, fInputPipeWrite, fOutputPipeRead, fOutputPipeWrite: Cardinal; fProcess: Cardinal; procedure FClbProc(Sender: TObject; const ABuffer: String; ABufSize: Cardinal); procedure FOpenProcess; procedure FCloseProcess; procedure FWriteToStdIn(const AText: String); { Private declarations } public { Public declarations } end; TPipeClbProc = procedure(Sender: TObject; const ABuffer: String; ABufSize: Cardinal) of Object; TPipeReadThread = class(TThread) private fBuffer: String; fBytesRead: Cardinal; fClbProc: TPipeClbProc; fPipeOutput: Cardinal; procedure FSyncProc; protected procedure Execute; override; constructor Create(AClbProc: TPipeClbProc; APipeOutput: Cardinal); end; var Form1: TForm1; implementation {$R *.dfm} {================================================= =============================} constructor TPipeReadThread.Create(AClbProc: TPipeClbProc; APipeOutput: Cardinal); begin inherited Create(True); fClbProc := AClbProc; fPipeOutput := APipeOutput; SetLength(fBuffer, 5000); FreeOnTerminate := True; Resume; end; {================================================= =============================} procedure TPipeReadThread.Execute; var LBufSize: Cardinal; LRes : Boolean; begin LBufSize := Length(fBuffer); repeat LRes := ReadFile(fPipeOutput, fBuffer[1], LBufSize, fBytesRead, nil); Synchronize(fSyncProc); until not(LRes) or Terminated; end; {================================================= =============================} procedure TPipeReadThread.FSyncProc; begin fClbProc(Self, fBuffer, fBytesRead); end; {================================================= =============================} {================================================= =============================} {================================================= =============================} procedure TForm1.FClbProc(Sender: TObject; const ABuffer: String; ABufSize: Cardinal); var LNew: String; LPos: Integer; begin LNew := copy(ABuffer, 1, ABufSize); LPos := pos(#$C, LNew); if (LPos > 0) then begin MemoOutput.Text := ''; LNew := copy(LNew, LPos + 1, Length(LNew)); end; MemoOutput.Text := MemoOutput.Text + LNew; PostMessage(MemoOutput.Handle, WM_VSCROLL, SB_BOTTOM, 0); end; {================================================= =============================} procedure TForm1.FOpenProcess; var LStartupInfo: TStartupInfo; LProcessInfo: TProcessInformation; LSecurityAttr: TSECURITYATTRIBUTES; LSecurityDesc: TSecurityDescriptor; begin FillChar(LSecurityDesc, SizeOf(LSecurityDesc), 0); InitializeSecurityDescriptor(@LSecurityDesc, SECURITY_DESCRIPTOR_REVISION); SetSecurityDescriptorDacl(@LSecurityDesc, True, nil, False); LSecurityAttr.nLength := SizeOf(LSecurityAttr); LSecurityAttr.lpSecurityDescriptor := @LSecurityDesc; LSecurityAttr.bInheritHandle := True; fProcess := 0; if CreatePipe(fInputPipeRead, fInputPipeWrite, @LSecurityAttr, 0) then //Input-Pipe begin if CreatePipe(fOutputPipeRead, fOutputPipeWrite, @LSecurityAttr, 0) then //Output-Pipe begin FillChar(LStartupInfo, SizeOf(LStartupInfo), 0); FillChar(LProcessInfo, SizeOf(LProcessInfo), 0); LStartupInfo.cb := SizeOf(LStartupInfo); LStartupInfo.hStdOutput := fOutputPipeWrite; LStartupInfo.hStdInput := fInputPipeRead; LStartupInfo.hStdError := fOutputPipeWrite; LStartupInfo.dwFlags := STARTF_USESTDHANDLES or STARTF_USESHOWWINDOW; LStartupInfo.wShowWindow := SW_HIDE; if CreateProcess(nil, 'cmd', @LSecurityAttr, nil, True, 0, nil, nil, LStartupInfo, LProcessInfo) then begin fProcess := LProcessInfo.hProcess; TPipeReadThread.Create(FClbProc, fOutputPipeRead); end else begin CloseHandle(fInputPipeRead); CloseHandle(fInputPipeWrite); CloseHandle(fOutputPipeRead); CloseHandle(fOutputPipeWrite); end; end else begin CloseHandle(fInputPipeRead); CloseHandle(fInputPipeWrite); end; end end; {================================================= =============================} procedure TForm1.FCloseProcess; begin if (fProcess <> 0) then begin CloseHandle(fInputPipeRead); CloseHandle(fInputPipeWrite); CloseHandle(fOutputPipeRead); CloseHandle(fOutputPipeWrite); TerminateProcess(fProcess, 0); fProcess := 0; end; end; {================================================= =============================} procedure TForm1.FWriteToStdIn(const AText: String); var LPos, LWritten: Cardinal; LRes : Boolean; begin LPos := 1; repeat LWritten := 0; LRes := WriteFile(fInputPipeWrite, AText[LPos], Cardinal(Length(AText)) - LPos + 1, LWritten, nil); inc(LPos, LWritten); until not(LRes) or (LPos > Cardinal(Length(AText))); end; {================================================= =============================} procedure TForm1.FormCreate(Sender: TObject); begin fProcess := 0; FOpenProcess; end; {================================================= =============================} procedure TForm1.FormClose(Sender: TObject; var Action: TCloseAction); begin FCloseProcess; end; {================================================= =============================} {================================================= =============================} procedure TForm1.Button1Click(Sender: TObject); VAR e: INTEGER; begin e := ShellExecute (Handle, NIL, PCHAR('C:\Dokumente und Einstellungen\Administrator\Desktop\Alarm\NEF.BAT' ), PCHAR(''), NIL, SW_SHOW); IF (e<=32) THEN begin ShowMessage('Fehler: Batch-Datei konnte nicht ausgeführt werden!') end end; end. batchdatei zum test ping localhost probiert mal |
Re: cmd fenster
wer kann mir weiter helfen ?
kann auch das ganze programm schicken !! |
Re: cmd fenster
Hi,
Du brauchst nicht innerhalb 30 Minuten zu pushen, dazu keine Delphi-Tags um den Code. |
Re: cmd fenster
Hallo,
lass das mit dem ShellExecute weg und folge dem Beispiel. ![]() Heiko |
Re: cmd fenster
als erstes die Delphi-Tags nachträglich setzen (den Beitrag kannst du mit dem Edit-button nachträglich bearbeiten) und als nächstes uns deine Delphiversion verraten.
|
Re: cmd fenster
was heißt delphi tags ??? ich bin doch ganz neu dabei
versuche seit zwei tagen mit delphi 5 zu arbeiten |
Re: cmd fenster
Delphi-Quellcode:
< Das sind die Delphi-Tags. Wenn Du die um Deinen Code machst, wird der farblich korrekt dargestellt.
<Hier Code hin>
|
Re: cmd fenster
Hallo,
mit Tags ist das Forum hier gemeint, nicht Delphi selber. Markier den Delphi-Code im Edit-Fenster und klciek oben auf Delphi-Code. Ah ja und willkommen bei Delphi ;) Heiko |
Re: cmd fenster bekomme es einfach nicht hin
hallo bekomme es einfach nicht hin:
wenn button 1 eine bachdatei ausführt soll sie in meiner console angezeigt werden und nicht wo anders was mache ich falsch :wall: :wall: schaut euch den quelltext an und ändert in bitte danke unit Unit1; interface uses Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls, ShellAPI; type TForm1 = class(TForm) MemoOutput: TMemo; EdCmd: TEdit; BtnWriteCmd: TButton; Button1: TButton; procedure FormCreate(Sender: TObject); procedure FormClose(Sender: TObject; var Action: TCloseAction); procedure BtnWriteCmdClick(Sender: TObject); procedure EdCmdKeyPress(Sender: TObject; var Key: Char); procedure Button1Click(Sender: TObject); private fInputPipeRead, fInputPipeWrite, fOutputPipeRead, fOutputPipeWrite: Cardinal; fProcess: Cardinal; procedure FClbProc(Sender: TObject; const ABuffer: String; ABufSize: Cardinal); procedure FOpenProcess; procedure FCloseProcess; procedure FWriteToStdIn(const AText: String); { Private declarations } public { Public declarations } end; TPipeClbProc = procedure(Sender: TObject; const ABuffer: String; ABufSize: Cardinal) of Object; TPipeReadThread = class(TThread) private fBuffer: String; fBytesRead: Cardinal; fClbProc: TPipeClbProc; fPipeOutput: Cardinal; procedure FSyncProc; protected procedure Execute; override; constructor Create(AClbProc: TPipeClbProc; APipeOutput: Cardinal); end; var Form1: TForm1; implementation {$R *.dfm} constructor TPipeReadThread.Create(AClbProc: TPipeClbProc; APipeOutput: Cardinal); begin inherited Create(True); fClbProc := AClbProc; fPipeOutput := APipeOutput; SetLength(fBuffer, 5000); FreeOnTerminate := True; Resume; end; procedure TPipeReadThread.Execute; var LBufSize: Cardinal; LRes : Boolean; begin LBufSize := Length(fBuffer); repeat LRes := ReadFile(fPipeOutput, fBuffer[1], LBufSize, fBytesRead, nil); Synchronize(fSyncProc); until not(LRes) or Terminated; end; procedure TPipeReadThread.FSyncProc; begin fClbProc(Self, fBuffer, fBytesRead); end; procedure TForm1.FClbProc(Sender: TObject; const ABuffer: String; ABufSize: Cardinal); var LNew: String; LPos: Integer; begin LNew := copy(ABuffer, 1, ABufSize); LPos := pos(#$C, LNew); if (LPos > 0) then begin MemoOutput.Text := ''; LNew := copy(LNew, LPos + 1, Length(LNew)); end; MemoOutput.Text := MemoOutput.Text + LNew; PostMessage(MemoOutput.Handle, WM_VSCROLL, SB_BOTTOM, 0); end; procedure TForm1.FOpenProcess; var LStartupInfo: TStartupInfo; LProcessInfo: TProcessInformation; LSecurityAttr: TSECURITYATTRIBUTES; LSecurityDesc: TSecurityDescriptor; begin FillChar(LSecurityDesc, SizeOf(LSecurityDesc), 0); InitializeSecurityDescriptor(@LSecurityDesc, SECURITY_DESCRIPTOR_REVISION); SetSecurityDescriptorDacl(@LSecurityDesc, True, nil, False); LSecurityAttr.nLength := SizeOf(LSecurityAttr); LSecurityAttr.lpSecurityDescriptor := @LSecurityDesc; LSecurityAttr.bInheritHandle := True; fProcess := 0; if CreatePipe(fInputPipeRead, fInputPipeWrite, @LSecurityAttr, 0) then //Input-Pipe begin if CreatePipe(fOutputPipeRead, fOutputPipeWrite, @LSecurityAttr, 0) then //Output-Pipe begin FillChar(LStartupInfo, SizeOf(LStartupInfo), 0); FillChar(LProcessInfo, SizeOf(LProcessInfo), 0); LStartupInfo.cb := SizeOf(LStartupInfo); LStartupInfo.hStdOutput := fOutputPipeWrite; LStartupInfo.hStdInput := fInputPipeRead; LStartupInfo.hStdError := fOutputPipeWrite; LStartupInfo.dwFlags := STARTF_USESTDHANDLES or STARTF_USESHOWWINDOW; LStartupInfo.wShowWindow := SW_HIDE; if CreateProcess(nil, 'cmd', @LSecurityAttr, nil, True, 0, nil, nil, LStartupInfo, LProcessInfo) then begin fProcess := LProcessInfo.hProcess; TPipeReadThread.Create(FClbProc, fOutputPipeRead); end else begin CloseHandle(fInputPipeRead); CloseHandle(fInputPipeWrite); CloseHandle(fOutputPipeRead); CloseHandle(fOutputPipeWrite); end; end else begin CloseHandle(fInputPipeRead); CloseHandle(fInputPipeWrite); end; end end; procedure TForm1.FCloseProcess; begin if (fProcess <> 0) then begin CloseHandle(fInputPipeRead); CloseHandle(fInputPipeWrite); CloseHandle(fOutputPipeRead); CloseHandle(fOutputPipeWrite); TerminateProcess(fProcess, 0); fProcess := 0; end; end; procedure TForm1.FWriteToStdIn(const AText: String); var LPos, LWritten: Cardinal; LRes : Boolean; begin LPos := 1; repeat LWritten := 0; LRes := WriteFile(fInputPipeWrite, AText[LPos], Cardinal(Length(AText)) - LPos + 1, LWritten, nil); inc(LPos, LWritten); until not(LRes) or (LPos > Cardinal(Length(AText))); end; procedure TForm1.FormCreate(Sender: TObject); begin fProcess := 0; FOpenProcess; end; procedure TForm1.FormClose(Sender: TObject; var Action: TCloseAction); begin FCloseProcess; end; procedure TForm1.BtnWriteCmdClick(Sender: TObject); begin FWriteToStdIn(EdCmd.Text + #13#10); EdCmd.Text := ''; end; procedure TForm1.EdCmdKeyPress(Sender: TObject; var Key: Char); begin if Key = #13 then begin Key := #0; BtnWriteCmdClick(nil); end; end; procedure TForm1.Button1Click(Sender: TObject); VAR e: INTEGER; begin e := ShellExecute (Handle, NIL, PCHAR('C:\Dokumente und Einstellungen\Administrator\Desktop\testus\NEF.BAT '), PCHAR(''), NIL, SW_SHOW); IF (e<=32) THEN begin ShowMessage('Fehler: Batch-Datei konnte nicht ausgeführt werden!') end end; end. [code] |
Re: cmd fenster
Moin, Moin technik05!
In Beitrag #24 wurde doch schon gesagt, vergiss das ShellExecute und verwende das Beispiel aus dsdt. Ich habe das heute auch mal verwendet, das funktioniert! |
Alle Zeitangaben in WEZ +1. Es ist jetzt 14:43 Uhr. |
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024-2025 by Thomas Breitkreuz