Autor Beitrag
Seraph
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 163

Windows.:siXPack:.
Delphi7 Professional
BeitragVerfasst: Do 10.04.08 14:13 
Hey ihr Freakse!

Ich wollt mal 'ne Frage bezüglich des fragwürdigen ShellExecutes.

Also entweder ich benutze die falsche Funktion oder ich bin zu blede was Anständiges im Internet zu finden:

Folgende Situation:
Ich habe einen Pool aus Programmen, die alle eine bestimmte Aufgabe erfüllen und
verschiedene Übergabeparameter weiterverarbeiten.

Die Programme sind Konsolen-Applikationen und ich rufe sie über ShellExecute auf:
ShellExecute(Application.Handle, 'open''.\pool\Programm.exe''-r 0'nil, SW_HIDE);

Schön und gut!
Aber kann ich mit ShellExecute auch herausfinden, was das Konsolenprogramm
für einen Rückgabewert hat?


Eines dieser Programme liest Beispielsweise den Status eines Gerätes aus und gibt diesen als Zahl zurück!

Bitte um schnelle Hilfe!
Der Karren brennt!
Seraph Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 163

Windows.:siXPack:.
Delphi7 Professional
BeitragVerfasst: Fr 11.04.08 09:24 
Push
Martin1966
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 1068

Win 2000, Win XP
Delphi 7, Delphi 2005
BeitragVerfasst: Fr 11.04.08 09:39 
Hallo! :wink2:

user profile iconSeraph hat folgendes geschrieben:
Push

Puschen ist hier erst nach 24h erlaubt. ;-)

Mit ShellExecute kannst du nicht mal eben die Ausgabe einer Konsolenanwendung zurück erhalten.

Hier in der Delphi-Library existiert aber ein passender Beitrag: Wie kann man ein Konsolen-Kommando ausführen und das Ergebnis zurückliefern?

Lg, Martin

_________________
Ein Nutzer der Ecke ;-)
Seraph Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 163

Windows.:siXPack:.
Delphi7 Professional
BeitragVerfasst: Fr 11.04.08 10:07 
Titel: DAAAAANKKEEEE!
Hey Cool! :D

Danke Martin! :dance:

Zitat:
@Narses:
Bei Gelegenheit werde ich dir einen Tempel bauen!


Gruß an Alle,
Seraph
Seraph Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 163

Windows.:siXPack:.
Delphi7 Professional
BeitragVerfasst: Mi 16.04.08 14:27 
Titel: Kann keine weiteren Prozess-Instanzen Forken
Hi Leute!

Also ich führe meine Programme jetzt mit CreateProcess() aus und hole den Rückgabewert via GetExitCodeProcess() zurück, nachdem der Prozess beendet wurde.
(Warten bis der Prozess beendet wurde, mit WaitForSingleObject() )

Funktioniert einwandfrei! Sau cool!

ABER!!!!

Ich rufe ein Programm mit einem Timer alle 500 Millisekunden auf!
Nach einer Weile kann ich jedoch kein weiteres Programm mehr aufrufen!
Also egal welches! Ich kann keine Prozesse mehr starten!

Gut, Ich net blöd, denk natürlich darüber nach und vermute natürlich als erstes,
dass er mir die Prozesse vielleicht nicht wieder beendet und Windows irgendwann keinen weiteren Prozess mehr verwalten/starten kann.
Aber dann würde ja nach WaitForSingleObject() nix passieren oder?
Habs auch schon mit TerminateProcess probiert!

Kann es also irgendwie sein, dass Windows zwar die Prozesse beendet, aber nicht die
Konsolen-Instanzen????

Was mache ich falsch?

Danke schonmal im Voraus!

Gruß,
Seraph

Ich habe an Narses Code nichts verändert!
Habs auch mal nur mit den wesentlichen Zeilen probiert:
ausblenden volle Höhe Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
function exec(ShellCommand: String): Cardinal;
var
 StartupInfo: TStartupInfo;
 ProcessInfo: TProcessInformation;
 cReturnCode: Cardinal;
begin
 FillChar(StartupInfo,SizeOf(TStartupInfo),#0);
 StartupInfo.cb := SizeOf(StartupInfo);
 StartupInfo.hStdInput := 0;

 StartupInfo.wShowWindow := SW_HIDE;

 CreateProcess(NIL,
               PChar(ShellCommand),
               NIL,
               NIL,
               TRUE,
               CREATE_NO_WINDOW,
               NIL,
               NIL,
               StartupInfo,
               ProcessInfo);

  WaitForSingleObject(ProcessInfo.hProcess,INFINITE);

  GetExitCodeProcess(ProcessInfo.hProcess, cReturnCode);

  CloseHandle(ProcessInfo.hProcess);

  exec := cReturnCode;
end;


Funzt zwar, aber immer noch das selbe Problem!

Zusatzinfo:
Wenn ich ein exec auf demselben Rechner über PHP starte, dann meint er nur soviel wie:
Could not fork bla/bla/blubb.exe
AHT
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 207



BeitragVerfasst: Mi 16.04.08 14:58 
Mal eine ganz dummme Frage: Wo wartest du dort auf ein Prozessende?
Seraph Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 163

Windows.:siXPack:.
Delphi7 Professional
BeitragVerfasst: Mi 16.04.08 15:17 
In Zeile 24. Oder etwa nicht?
Seraph Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 163

Windows.:siXPack:.
Delphi7 Professional
BeitragVerfasst: Do 17.04.08 18:22 
Hat das noch nie jemand so gehört/gesehen?
Oder ist vielleicht mein WINDOOF im A*R*S*C*H ?
Martok
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 3661
Erhaltene Danke: 604

Win 8.1, Win 10 x64
Pascal: Lazarus Snapshot, Delphi 7,2007; PHP, JS: WebStorm
BeitragVerfasst: Do 17.04.08 20:43 
Der Code stimmt schon, aber so schnell Prozesse zu forken, das klappt unter Windoof nicht.

Wäre es nicht einfacher, dass Gerät selber abzufragen?

@Prozesse nicht mehr starten können: sieht wie user profile iconAHT's Spezialgebiet aus ;)

_________________
"The phoenix's price isn't inevitable. It's not part of some deep balance built into the universe. It's just the parts of the game where you haven't figured out yet how to cheat."