| |
|
|
| Fundstück de Andreas Miethe en Edición de Konsolenanwendungen einzulesen: DirektDosOutputToMultiedit
Andreas Miethe (30.05.2010 18:52)
XProfan11 - Code Gruss Andreas KompilierenMarcaSeparación $H Windows.ph
$H Structs.ph
Struct PROCESS_INFORMATION = ~PROCESS_INFORMATION
Struct SECURITY_ATTRIBUTES = ~SECURITY_ATTRIBUTES
Struct STARTUPINFO = ~STARTUPINFO
DEF &NORMAL_PRIORITY_CLASS $20
DEF &STARTF_USESTDHANDLES $100
DEF &STARTF_USESHOWWINDOW $1
CLS ~GetSysColor(~COLOR_BTNFACE)
SetDialogFont ~GetStockObject(~ANSI_VAR_FONT)
Var Ende& = 0
Var Multi& = Create("MultiEdit",%hwnd,"",1,10,500,400)
Var Button& = Create("Button",%hwnd,"Start",540,10,80,24)
Var Button1& = Create("Button",%hwnd,"Ende",540,40,80,24)
Whilenot Ende&
Waitinput
If Clicked(Button1&)
Ende& = 1
ElseIf Clicked(Button&)
SetText Multi&,""
Beispiel mit "dir"
DirektDosOutputToMultiedit("",GetComspec()+" /c dir C:\xprofan11\*.* /r",255,Multi&)
Endif
EndWhile
End
Proc GetComspec
Commandshell ermitteln
Return SubStr$(GetEnv$("COMSPEC"), -1, "\")
EndProc
Proc DirektDosOutputToMultiedit
Parameters Progname$,Command$,MemBuffer&,Multiedit&
Declare hRPipe&,hWPipe&,pRBytes&,Result&
Declare PI#,SI#,SA#
Dim PI#,PROCESS_INFORMATION
Dim SI#,STARTUPINFO
Dim SA#,SECURITY_ATTRIBUTES
Declare StringBuffer$
StringBuffer$ = Space$(MemBuffer&)
SA#.nLength& =SizeOf(SA#)
SA#.bInheritHandle& = 1
SA#.lpSecurityDescriptor& = 0
Result& = ~CreatePipe(Addr(hRPipe&), Addr(hWPipe&), SA#, 0)
If Result& = 0
MessageBox("Pipe konnte nicht gestartet werden","",0)
End
Endif
If Progname$ <> ""
Command$ = " " + Command$
Endif
SI#.cb& = SizeOf(SI#)
SI#.dwFlags& = &STARTF_USESHOWWINDOW | &STARTF_USESTDHANDLES
SI#.hStdOutput& = hWPipe&
SI#.hStdError& = hWPipe&
If Progname$ = ""
Result& = ~CreateProcess(0, Addr(Command$), SA#, SA#, 1, &NORMAL_PRIORITY_CLASS, 0, 0, SI#,PI#)
Else
Result& = ~CreateProcess(Addr(Progname$), Addr(Command$),SA#,SA#,1,&NORMAL_PRIORITY_CLASS, 0, 0,SI#,PI#)
Endif
If Result& <> 1
MessageBox("Datei nicht gefunden","",0)
End
Else
Endif
Result& = ~CloseHandle(hWPipe&)
Var out$ = ""
While Result& <> 0
Result& = ~ReadFile(hRPipe&,Addr(StringBuffer$),MemBuffer&,Addr(pRBytes&), 0)
If pRBytes& > 0
Out$ = Left$(StringBuffer$,pRBytes&)
~OemToChar(Addr(Out$),Addr(Out$))
statt in ein Multiedit kann der Output natürlich auch in eine Datei geschrieben werden
Settext Multiedit&,GetText$(Multiedit&)+Out$
Endif
Endwhile
~CloseHandle(PI#.hProcess&)
~CloseHandle(PI#.hThread&)
~CloseHandle(hRPipe&)
Disponer PI#,SI#,SA#
ENDPROC
Kürzeres KompilierenMarcaSeparaciónmacht Umweg una Expediente nfo.txt. |
|
|
| |
|
|