Autor Beitrag
kandesbunzler
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 116
Erhaltene Danke: 1


Delphi 7, XE2
BeitragVerfasst: Di 18.11.08 19:52 
Hallo allerseits,

ich möchte mit shellexecute eine Kommandozeile mit Pfadangabe starten.

Bsp: "c:\program files\meine programme".

Dummerweise wird in der DOS-Box nur bis "c:\program" interpretiert, d.h. nach dem Leerzeichen geht es nicht weiter.

Was könnte die Ursache sein?

Auf bald ...
kandesbunzler.
AXMD
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 4006
Erhaltene Danke: 7

Windows 10 64 bit
C# (Visual Studio 2019 Express)
BeitragVerfasst: Di 18.11.08 19:56 
Hallo!

Setz den Pfad doch einfach unter doppelte Anführungszeichen, z.B.:

ausblenden Delphi-Quelltext
1:
'"c:\program files\meine programme\test.exe"'					


AXMD
kandesbunzler Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 116
Erhaltene Danke: 1


Delphi 7, XE2
BeitragVerfasst: Di 18.11.08 21:56 
Hallo,

das habe ich schon (sorry für mein unvollständige Schreibweise). Genau in der Form, wie Du beschrieben hast, wird im DOS-Fenster nach dem ersten Leerzeichen abgebrochen und damit der Rest nicht 'gefunden'.

Auf bald ...
kandesbunzler.
Xentar
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 2077
Erhaltene Danke: 2

Win XP
Delphi 5 Ent., Delphi 2007 Prof
BeitragVerfasst: Di 18.11.08 22:00 
Dann machst du was falsch.
Normalerweise sollten es dir "" tun.
Zeig mal den Code.

_________________
PROGRAMMER: A device for converting coffee into software.
kandesbunzler Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 116
Erhaltene Danke: 1


Delphi 7, XE2
BeitragVerfasst: Di 18.11.08 22:33 
Dann will ich mal versuchen :-) :

1. Kommandozeile := '/K ' + '"' + Pfad_zu_EXE + '"';
2. shellexecute (handle, 'open', PCHAR ('cmd.exe '), PChar (Kommandozeile), nil, Sw_ShowNormal);

Zumindest im Debugger wird die Kommandozeile als String korrekt übergeben. Der Parameter '/K ' verhindert das automatische Schließen der DOS-Box (solange ich noch bei der Fehlersuche bin ...). Allerdings besteht das Problem auch ohne '/K ' ...

Auf bald ...
kandesbunzler.
AXMD
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 4006
Erhaltene Danke: 7

Windows 10 64 bit
C# (Visual Studio 2019 Express)
BeitragVerfasst: Di 18.11.08 22:37 
Dann ist die Sache ja relativ klar: du übergibst ja den ganzen EXE-Pfad noch einmal als Parameter. Entweder du führst ein Escaping der doppelten Anführungszeichen durch, damit cmd.exe diese auch als solche erkennt (siehe markierte Stellen unten) oder du machst das Ganze einfach ohne cmd.exe und verzichtest darauf, dass sich die EXE wieder selbst nach ihrer Beeindigung schließt.

user profile iconkandesbunzler hat folgendes geschrieben Zum zitierten Posting springen:
1. Kommandozeile := '/K ' + '^"' + Pfad_zu_EXE + '^"';
2. shellexecute (handle, 'open', PCHAR ('cmd.exe '), PChar (Kommandozeile), nil, Sw_ShowNormal);


AXMD
Xentar
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 2077
Erhaltene Danke: 2

Win XP
Delphi 5 Ent., Delphi 2007 Prof
BeitragVerfasst: Di 18.11.08 22:39 
Kann es sein, dass du in Pfad_zu_EXE auch nochmal Anführungsstriche drin hast?

_________________
PROGRAMMER: A device for converting coffee into software.
AXMD
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 4006
Erhaltene Danke: 7

Windows 10 64 bit
C# (Visual Studio 2019 Express)
BeitragVerfasst: Di 18.11.08 22:42 
user profile iconXentar hat folgendes geschrieben Zum zitierten Posting springen:
Kann es sein, dass du in Pfad_zu_EXE auch nochmal Anführungsstriche drin hast?


Das ist noch ein guter Punkt. Hier in Kombination mit dem von mir oben erwähnten Escaping ein Beispiel, das funktioniert:

ausblenden Quelltext
1:
cmd.exe /K ^"C:\Program Files\Adobe\Reader 9.0\Reader\acrord32.exe^"					


Man beachte hier wieder das Escaping der doppelten Anführungszeichen.

AXMD


//EDIT: Crosspost DP
Xentar
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 2077
Erhaltene Danke: 2

Win XP
Delphi 5 Ent., Delphi 2007 Prof
BeitragVerfasst: Di 18.11.08 22:46 
user profile iconAXMD hat folgendes geschrieben Zum zitierten Posting springen:
ausblenden Quelltext
1:
cmd.exe /K ^"C:\Program Files\Adobe\Reader 9.0\Reader\acrord32.exe^"					


Man beachte hier wieder das Escaping der doppelten Anführungszeichen.


Hm, wenn ich das unter Start -> Ausführen reinhacke, bekomme ich trotzdem den Fehler
Zitat:
Der Befehl "C:\Program" ist entweder falsch geschrieben oder
konnte nicht gefunden werden.

_________________
PROGRAMMER: A device for converting coffee into software.
AXMD
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 4006
Erhaltene Danke: 7

Windows 10 64 bit
C# (Visual Studio 2019 Express)
BeitragVerfasst: Di 18.11.08 22:54 
Wenn du den Aufruf aus einem Eingabeaufforderungsfenster heraus startest funktioniert er nur mit dem Escaping, unter Start Ausführen nur ohne.

AXMD
kandesbunzler Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 116
Erhaltene Danke: 1


Delphi 7, XE2
BeitragVerfasst: Mi 19.11.08 10:49 
Hallo allerseits,

ich habe mal einen Screenshot angehangen, welcher das Ziel genauer zeigt.
Ich muß Pfad und aufrufendes Programm in Doppelhochkomma starten, gefolgt von den Parametern, welche tws. ebenfalls in Doppelhochkomma eingeschlossen sind.

Auf bald ...
kandesbunzler.
Einloggen, um Attachments anzusehen!
AXMD
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 4006
Erhaltene Danke: 7

Windows 10 64 bit
C# (Visual Studio 2019 Express)
BeitragVerfasst: Mi 19.11.08 10:51 
Funktioniert es denn jetzt mit den Hinweisen, die wir dir gegeben haben? Poste bitte deinen aktuellen Quelltext.

AXMD
kandesbunzler Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 116
Erhaltene Danke: 1


Delphi 7, XE2
BeitragVerfasst: Mi 19.11.08 11:38 
Hallo allerseits,

unter Verwendung des Befehles:

---BEGIN
Kommandozeile := '/K ' + '^"' + Pfad_zu_EXE + '^"' + ' /xyz-' + ' /abcdef /ft\"Mein Logo\" /ca';
shellexecute (handle, 'open', PCHAR ('cmd.exe '), PChar (Kommandozeile), nil, Sw_ShowNormal);
---END

erhalte ich in der DOS-Box:

---BEGIN
'"C:\Program' is not recognized as an internal or external command,
operable program or batch file.
---END

Den Wert von Pfad_zu_EXE ermittle ich aus OpenDialog.

Wie gesagt, im Debugger steht der Inhalt, wie er sein soll, aber leider wird dieser offensichtlich nicht in der korrekten Form übergeben.

Auf bald ...
kandesbunzler.
AXMD
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 4006
Erhaltene Danke: 7

Windows 10 64 bit
C# (Visual Studio 2019 Express)
BeitragVerfasst: Mi 19.11.08 11:58 
Warum führtst du das Escaping einmal mit Zirkumflex (^) und einmal mit Backslash durch? Wenn dann nur mit Zirkumflex oder du versuchst (wie oben geschrieben) vollständig auf das Escapting zu verzichten. Wie ist dann das Ergebnis?

AXMD
kandesbunzler Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 116
Erhaltene Danke: 1


Delphi 7, XE2
BeitragVerfasst: Mi 19.11.08 15:07 
Hallo,

vielleicht habe ich mich auch nicht genau genug ausgedrückt. Ich muß die gesamte Zeile in der DOS-Box aufrufen, d.h. einschließlich aller Zahlen, Zeichen, Sonderzeichen etc. Das Beispiel zeigt den KOMPLETT zu übergebenden Befehl (einschließlich aller doppelten Hochkomma, Slashes & Backslashes, Parameter - einfach ALLES):

"c:\Program Files\Mein Programm" /abc-1234567 /xyz123456 /xy\"Mein Kommentar\" /ab

Ergo, ich darf keine Zeichen o.ä. escapen.

Auf bald ...
kandesbunzler.
AXMD
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 4006
Erhaltene Danke: 7

Windows 10 64 bit
C# (Visual Studio 2019 Express)
BeitragVerfasst: Mi 19.11.08 15:12 
user profile iconkandesbunzler hat folgendes geschrieben Zum zitierten Posting springen:
"c:\Program Files\Mein Programm" /abc-1234567 /xyz123456 /xy\"Mein Kommentar\" /ab


Was ist dann das, wenn kein Escaping? Und noch einmal: Poste bitte deinen aktuellen Code!

AXMD