![]() |
DosCommand in Konsolenanwendung, identifier not found
Hallo,
Aufgabenbeschreibung: eine Konsolenanwendung, soll eine andere Konsolenanwendung auslesen, und den Wert verarbeiten und dann speichern. Mit einem Grafischen Windowsprogramm ist das kein Problem:
Delphi-Quellcode:
uses ... DosCommand_2009 ...
Delphi-Quellcode:
TForm1 = class(TForm)
DosCommand1: TDosCommand; ... var cmd: TDoscommand; ... Aber wie geht das gleiche mit einer Konsolenanwendung?? Über Projekteinstellungen/Projektinspektor DosCommand_2009 aufgenommen.
Delphi-Quellcode:
Error:... TMyApplication = class(TCustomApplication) protected procedure DoRun; override; public DosCommand1: TDosCommand; constructor Create(TheOwner: TComponent); override; destructor Destroy; override; procedure WriteHelp; virtual; end;
Delphi-Quellcode:
Aber warum?
project1.lpr(20,29) Error: Identifier not found "TDosCommand"
Nehme DosCommand_2009 aus dem Projektinspektor raus und schreibe es selbst ins Uses, dann meckert er weiter " Error: Identifier not found "graphics"" in DosCommand_2009.... Woran liegt es? LG Monday |
AW: DosCommand in Konsolenanwendung, identifier not found
Ausgehend von Deiner Aufgabenstellung würdest Du eher sowas benötigen:
Delphi-Quellcode:
Das Programm liest die Ausgabe einer Konsolenanwendung und schreibt sie in eine Datei, gibt sie aber auch gleichzeitig auf der Konsole aus.
program Tee;
{$APPTYPE CONSOLE} var line : string; sFile : string; fFile : TextFile; begin if ParamCount in [1..2] then begin sFile := ParamStr(1); end else begin WriteLn('Syntax: tee Ausgabedatei'); WriteLn; WriteLn(' tee SchreibDieAusgabeHierHin.txt'); WriteLn; WriteLn(' tee SchreibDieAusgabeHierHin.txt append'); WriteLn(' (Die Ausgabe wird an die bestehende Datei angehangen.)'); WriteLn; halt(255); end; AssignFile(input, ''); // stdin AssignFile(output, ''); // stdout AssignFile(fFile, sFile); Reset(input); Rewrite(output); case ParamCount of 2 : begin if ParamStr(2)[1] in ['A','a'] then begin {$I-} Append(fFile); if IOResult <> 0 then Rewrite(fFile); {$I+} end else begin Rewrite(fFile); end; end; else Rewrite(fFile); end; while not Eof do begin ReadLn(line); WriteLn(line); WriteLn(fFile,line); end; CloseFile(fFile); CloseFile(output); CloseFile(input); end. Der Aufruf erfolgt dann z. B. in dieser Form:
Delphi-Quellcode:
In der Schleife
dir /s|tee InDieDateiSollGeschriebenWerden.txt
Delphi-Quellcode:
könntest Du natürlich dann beliebige Auswertungen, Verarbeitungen ... vornehmen.
while not Eof do begin
|
AW: DosCommand in Konsolenanwendung, identifier not found
Ok, Problem gelöst...
Ich musste bei der Konsolenanwendung noch die .pas Dateien über den Projektinspektor einfügen. Das war bei der Windows GUI nicht nötig. Warum auch immer... Trotzdem danke für die Mühe. LG Monday |
AW: DosCommand in Konsolenanwendung, identifier not found
Welche Dateien?
Und meine Vermutung geht in Richtung fehlende Default-Namespaces und alternativ noch zu fehlenden Suchpfaden. |
AW: DosCommand in Konsolenanwendung, identifier not found
Zitat:
|
AW: DosCommand in Konsolenanwendung, identifier not found
Irgendwie habe ich mir das einfacher vorgestellt:
Programm ruft Anwendung auf, sendet aber nichts an die Anwendung (??) und geht auch nicht auf DosCommand1NewLine . Warum? In diesem Beispiel erwarte ich jede Menge "111".
Delphi-Quellcode:
program project1;
{$mode delphi}{$H+} uses {$IFDEF UNIX}{$IFDEF UseCThreads} cthreads, {$ENDIF}{$ENDIF} Classes, SysUtils, CustApp, StrUtils, DosCommand_2009, interfaces { you can add units after this }; type { TMyApplication } TMyApplication = class(TCustomApplication) DosCommand1: TDosCommand; procedure DosCommand1NewLine(Sender: TObject; NewLine: string; OutputType: TOutputType); protected procedure DoRun; override; public constructor Create(TheOwner: TComponent); override; destructor Destroy; override; procedure WriteHelp; virtual; end; { TMyApplication } procedure TMyApplication.DosCommand1NewLine(Sender: TObject; NewLine: string; OutputType: TOutputType); begin writeln('1'); end; procedure TMyApplication.DoRun; var ErrorMsg: String; s : string; datei: string; begin // quick check parameters ErrorMsg:=CheckOptions('h','help'); if ErrorMsg<>'' then begin ShowException(Exception.Create(ErrorMsg)); Terminate; Exit; end; // parse parameters if HasOption('h','help') then begin WriteHelp; Terminate; Exit; end; { add your program here } DosCommand1 := TDoscommand.Create(self); DosCommand1.OnNewLine := DosCommand1NewLine; //??? datei := 'cmd'; DosCommand1.CommandLine := datei; DosCommand1.Execute; DosCommand1.SendLine('dir',True); read(s); // stop program loop Terminate; end; constructor TMyApplication.Create(TheOwner: TComponent); begin inherited Create(TheOwner); StopOnException:=True; end; destructor TMyApplication.Destroy; begin inherited Destroy; end; procedure TMyApplication.WriteHelp; begin { add your help code here } writeln('Usage: ',ExeName,' -h'); end; var Application: TMyApplication; begin Application:=TMyApplication.Create(nil); Application.Title:='My Application'; Application.Run; Application.Free; end. |
AW: DosCommand in Konsolenanwendung, identifier not found
Vermutlich synchronisiert sich DOSCommand mit der VCL und da DU keine Messages verarbeitest, wird das auch nie ausgeführt?
|
Alle Zeitangaben in WEZ +1. Es ist jetzt 04:47 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