![]() |
Dos command
Hi Leute ...
Hab schon viel gegoogelt und bin leider noch zu keinem befriedigendem Ergebnis gekommen. Ich möchte Dos befehle in meiner Kommandozeilen app abschießen können und die Ausgabe via Writln oder was auch immer anzeigen. das dürfte mit
Delphi-Quellcode:
funktioniere... tuts aber nicht
ShellExecute( 0, 'open', 'cmd', PChar('/k '+command), NIL, SW_ShowNormal );
hat jemand einen Tipp für mich? LG Steffen |
AW: Dos command
Was ist abschießen*? Was ist command? Was funktioniert nicht?
*) Es vereinfacht die Verständigung ungemein, wenn man sich allgemein verständlich ausdrückt. **) Shellexecute hat auch einen Rückgabewert, den man eventuell mal abfragen könnte. |
AW: Dos command
Und was funktioniert nicht?
|
AW: Dos command
Da du die Ausgabe haben willst, solltest du dich mal mit dem Stichwort "Pipes" auseinandersetzen. Damit bekommst du dann die Ausgabe in dein Programm, mit ShellExecute führst du es nur aus.
Beispiele wären z.B. ![]() |
AW: Dos command
Zitat:
|
AW: Dos command
also um mal alle offenen Fragen zu beantworten ;)
- nicht dos sondern cmd kommandos - commands = Kommandos wie zB "dir" - abschießen = ausführen ;) - was nicht funktioniert? Irgendwie passiert nichts :/ LG |
AW: Dos command
Zitat:
|
AW: Dos command
wie meinst du das ?
|
AW: Dos command
|
AW: Dos command
Delphi-Quellcode:
>
DIR
![]() ![]() Zitat:
Zitat:
Zitat:
|
AW: Dos command
Es geht mir nicht nur um DIR sondern um Alle Befehle, welche ich in einem CMD Prompt executen kann. (ipconfig, dir, copy, usw usw )
Der Sinn liegt darin, das ich ein kleines commandline Tool bastle, indem ich verschiedene Befehle ausführen kann. hier möchte ich eben noch oben genannte DOS Befehle einbinden dh. Die Eingabe sieht dann ca so aus: execcmd <DOS-BEFEHL>. |
AW: Dos command
Bei mir funktioniert der Code. Hast Du denn nun endlich den Rückgabewert von ShellExecute ausgewertet? Was steht drin?
[edit] Oder was sagt diese Variante?
Delphi-Quellcode:
[/edit]
procedure ExecuteCommand(const command: string);
const ENV_VAR = '%COMSPEC%'; var comspec: string; ReturnValue: integer; begin SetLength(comspec, ExpandEnvironmentStrings(ENV_VAR, nil, 0) + 1); ExpandEnvironmentStrings(ENV_VAR, PChar(comspec), Length(comspec)); SetLength(comspec, StrLen(PChar(comspec))); if comspec <> '' then begin ReturnValue := ShellExecute(0, 'open', PChar(comspec), PChar('/k ' + command), nil, SW_SHOW); if ReturnValue < 33 then MessageBox(0, PChar(Format('Fehler bei ShellExecute: %d', [ReturnValue]) ), nil, MB_OK or MB_ICONERROR); end else MessageBox(0, 'Kommandointerpreter konnte nicht ermittelt werden.', nil, MB_OK or MB_ICONERROR); end; |
AW: Dos command
Das funktioniert echt gut! Aber wie krieg ich das in meine Consoleapp und nicht in das extra cmd Fenster ?
LG |
AW: Dos command
Dein Programm ist eine Konsolenanwendung? Dann wird das mit ShellExecute vermutlich nicht funktionieren. Wenn ich die Hilfe zu
![]() |
AW: Dos command
Jupp, du mußt dann die Handle deines Consolenfensters an die anderen Anwendungen übergeben,
nicht daß die sich noch eine eigene Console aufmachen. |
AW: Dos command
Ich gebe zu ich hab keinen Plan :(
|
AW: Dos command
Ich empfehle dir ein
![]() |
AW: Dos command
![]() |
AW: Dos command
Du möchtest eine Consolenanwendung erstellen, die ähnlich wie die CMD.EXE agiert, zusätzlich aber noch die Möglichkeit bietet, Abfragen an eine DB zu schicken.
Mir ist entfallen welche DB Du nutzt, aber ich möchte wetten, daß auch diese eine Möglichkeit bietet per Kommandozeile auf sie zuzugreifen. Vielleicht wäre es einfacher für Dich, bereits vorhandene Tools zu nutzen, als das Rad noch einmal neu zu erfinden? Gruß K-H |
AW: Dos command
Vielleicht ist das nen Blick wert:
![]() Hab damit mal ein eigenes "Konsolenfenster" programmiert und ihm Extrafeatures verpasst. Geht ja fast in deine Richtung. Gruß, Toni |
AW: Dos command
![]() |
AW: Dos command
Zitat:
|
AW: Dos command
also irgendwie krieg ichs nicht zum laufen ....
in dem Beispiel steht
Delphi-Quellcode:
Aber wenn ich die Unit einbinde bekomme ich bei DosCommand den CommandLine vorschlag nicht :/
var diskname: string;
-- DosCommand1.CommandLine := 'c:\myformat.bat a:'; DosCommand1.Execute; //launch format process DosCommand1.SendLine('', True); //equivalent to press enter key DiskName := 'test'; DosCommand1.SendLine(DiskName, True); //enter the name of the volume |
AW: Dos command
Zitat:
Delphi-Quellcode:
Tut bei mir einwandfrei
procedure TfrmTSMain.btnExecuteClick(Sender: TObject);
var Command : String; begin if JvOpenDialog.Execute then begin RxTrackInfo.EmptyTable; JvOpenDialog.InitialDir := ExtractFilePath(JvOpenDialog.FileName); lbxFileList.Items.Add(JvOpenDialog.FileName); mmMeta.Lines.Clear; mmDosCommand.Lines.Clear; Command := ExtractFilePath(Application.ExeName) + 'tsmuxer "' + JvOpenDialog.FileName + '"'; DosCommand.CommandLine := Command; DosCommand.Execute; end; end; |
AW: Dos command
Zitat:
|
AW: Dos command
Zitat:
|
AW: Dos command
Habe die Unit in meinen Libary Ordner gepackt und in die Uses eingebunden.
LG |
AW: Dos command
Zitat:
|
AW: Dos command
.. bin mir nicht sicher aber ist TDosCommand nicht eine Klasse?
.. hast Du davon eine Instanz erzeugt?
Delphi-Quellcode:
Grüße
dosCommand := TDosCommand.create;
Klaus |
AW: Dos command
Zitat:
ich teste mal die Unit ! LG |
AW: Dos command
da wo Du es benötigst als var
Delphi-Quellcode:
Grüße
dosCommand : TDosCommand;
Klaus |
AW: Dos command
Ich habe das jetzt so versucht:
Delphi-Quellcode:
Wie fange ich jetzt die Ausgabe ab ?
function execcmd(command : string) : string;
var error : string; RC : Cardinal; doscommand : TDosCommand; begin Writeln('Try to execute '+command+' ...'); //ExecuteCommand(command); doscommand := TDosCommand.Create(nil); doscommand.CommandLine := command; doscommand.Execute; end; LG Steffen |
AW: Dos command
Zitat:
Zitat:
|
Alle Zeitangaben in WEZ +1. Es ist jetzt 00:25 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 by Thomas Breitkreuz