Seite 2 von 3

Verfasst: 20.05.2009 18:14
von ts-soft
Und wo sind die Tüdelchen?

Verfasst: 20.05.2009 18:23
von X360 Andy
:?

Verfasst: 20.05.2009 18:32
von ts-soft
X360 Andy hat geschrieben::?

Code: Alles auswählen

File$ = SaveFileRequester("Bitte Datei zum Speichern auswählen", "", "Alle Dateien (*.*)|*.*", 0)
Rar_Pfad$ = Left(File$,Len(File$)-Len(GetExtensionPart(File$))) + "rar"
RunProgram("c:\Programme\WinRAR\rar.exe", "a " + #DQUOTE$ + Rar_Pfad$ + #DQUOTE$ +" " + #DQUOTE$ + GetFilePart(File$) + #DQUOTE$, GetPathPart(File$),#PB_Program_Hide|#PB_Program_Wait)
Noch nie was von langen Dateinamen gehört? Spaces in Pfaden und
Dateinamen? Die Tüdelchen braucht man seid Win95, nicht immer aber
immer öfter :mrgreen:

Verfasst: 20.05.2009 18:53
von X360 Andy
Du setzt also vor den Pfaden ein " ?
Hab ich vorher nie gehört un gemacht....

Naja du/ihr werdet es besser wissen :wink:

Eine kleine frage hätte ich gerade

Code: Alles auswählen

EnableExplicit

Define ping.l = RunProgram("ping", "google.com", "", #PB_Program_Open|#PB_Program_Read)
Define Output.s = ""
If ping
  While ProgramRunning(ping)
    Output + ReadProgramString(ping) + Chr(13)

  Wend
  CloseProgram(ping)
  Output + Chr(13) + Chr(13)
EndIf
MessageRequester("ping", Output)
Diesen Code habe gefunden beim suchen von dir.

Allerdings kann ich so ja nicht den aktuellen Status auslesen.
Ich bräuchte eig. nur was was mir die letzen 3 zahlen/zeichen der Konsole auslesen kann, also um damit die % Zahl hinten auszulesen.

Verfasst: 20.05.2009 19:07
von ts-soft
Ich weiß ja nicht was bei deiner Winversion in der Console steht :mrgreen:

Code: Alles auswählen

EnableExplicit

Define ping.l = RunProgram("ping", "google.com", "", #PB_Program_Open|#PB_Program_Read)
Define Output.s = ""
If ping
  While ProgramRunning(ping)
    Output + ReadProgramString(ping) + Chr(13)

  Wend
  CloseProgram(ping)
  Output + Chr(13) + Chr(13)
EndIf

Define Pos
Define.s FindString = "Mittelwert = "
Pos = FindString(Output, FindString, 1)
Debug Mid(Output, Pos + Len(FindString), 3)

Verfasst: 20.05.2009 19:12
von X360 Andy
Ne ich will ja von meinem RAR Code oben rausfinden wie weit er ist.

Dort wird ja der Status in Prozent angeben.

Und ich will während der Laufzeit rausfinden wie weit er ist, damit ich das ganze in einem Thread und einer Progressbar verwenden kann.

Ich hoffe man versteht was ich will :)

Verfasst: 20.05.2009 19:17
von Deluxe0321
quick and dirty.. ;)

Code: Alles auswählen

EnableExplicit

Procedure Lalelu(Dummy)
Protected ping.l = RunProgram("ping", "google.com", "", #PB_Program_Open|#PB_Program_Read|#PB_Program_Hide)
Protected Output.s = ""
If ping
  While ProgramRunning(ping)
    If IsGadget(0)
      Output.s = ReadProgramString(ping)
      Debug Output.s
      AddGadgetItem(0,-1,Output.s)
    EndIf
  Wend
  CloseProgram(ping)
EndIf
EndProcedure

OpenWindow(0,0,0,300,240,"Plong....")
ListViewGadget(0,0,0,300,240)

CreateThread(@LaLeLu(),0)
Repeat: Until WaitWindowEvent() = #PB_Event_CloseWindow
Gruß Marv

Verfasst: 20.05.2009 19:23
von X360 Andy
Danke aber funktionieren tut es noch nicht ganz

Code: Alles auswählen

Procedure Lalelu(Dummy)
File$ = SaveFileRequester("Bitte Datei zum Speichern auswählen", "", "Alle Dateien (*.*)|*.*", 0)
Rar_Pfad$ = Left(File$,Len(File$)-Len(GetExtensionPart(File$))) + "rar"
ping.l = RunProgram("c:\Programme\WinRAR\rar.exe", "a " + #DQUOTE$ + Rar_Pfad$ + #DQUOTE$ +" " + #DQUOTE$ + GetFilePart(File$) + #DQUOTE$, GetPathPart(File$),#PB_Program_Open|#PB_Program_Read|#PB_Program_Hide) 
If ping
  While ProgramRunning(ping)
    If IsGadget(0)
      Output.s = ReadProgramString(ping)
      Debug Output.s
      AddGadgetItem(0,-1,Output.s)
    EndIf
  Wend
  CloseProgram(ping)
EndIf
EndProcedure


OpenWindow(0,0,0,300,240,"Plong....")
ListViewGadget(0,0,0,300,240)

CreateThread(@LaLeLu(),0)
Repeat: Until WaitWindowEvent() = #PB_Event_CloseWindow
Wenn ich das starte und eine Datei auswähle (30MB) dann wird mir der % Status erst am ende angezeigt wenn die Rar datei schon fertig ist

Verfasst: 20.05.2009 19:39
von Deluxe0321
hmm.. komisch, scheint wirklich nicht zu funktionieren.. gut dann eine etwas umgebaute API-Lastige Variante aus dem Codearchive.. (hoffe nicht zu kompliziert)

Code: Alles auswählen

; English forum: http://purebasic.myforums.net/viewtopic.php?t=6544&highlight=
; Author: Rings
; Date: 13. June 2003


; Redirect the output from a compiler ....


; Redirect Outputs into Memory
; coded by Siegfried Rings march 2002
; redirected the PIPES
;
;see http://support.microsoft.com/default.aspx?scid=kb;EN-US;q173085
;

File$ = SaveFileRequester("Bitte Datei zum Speichern auswählen", "", "Alle Dateien (*.*)|*.*", 0)
Rar_Pfad$ = Left(File$,Len(File$)-Len(GetExtensionPart(File$))) + "rar"



mCommand.s="c:\Programme\WinRAR\rar.exe a " + #DQUOTE$ + Rar_Pfad$ + #DQUOTE$ +" " + #DQUOTE$ + File$ + #DQUOTE$
Debug mCommand.s

;Structure used by the CreateProcessA function
;another then that Fred implemented !
Structure MySTARTUPINFO
  cb.l
  lpReserved.l
  lpDesktop.l
  lpTitle.l
  dwX.l
  dwY.l
  dwXSize.l
  dwYSize.l
  dwXCountChars.l
  dwYCountChars.l
  dwFillAttribute.l
  dwFlags.l
  wShowWindow.w
  cbReserved2.w
  lpReserved2.l
  hStdInput.l
  hStdOutput.l
  hStdError.l
EndStructure

proc.PROCESS_INFORMATION ;Process info filled by CreateProcessA
ret.l ;long variable For get the Return value of the
start.MySTARTUPINFO ;StartUp Info passed To the CreateProceeeA
sa.SECURITY_ATTRIBUTES ;Security Attributes passeed To the
hReadPipe.l ;Read Pipe handle created by CreatePipe
hWritePipe.l ;Write Pite handle created by CreatePipe
lngBytesread.l ;Amount of byte Read from the Read Pipe handle
strBuff.s=Space(256) ;String buffer reading the Pipe

;Consts For functions
#NORMAL_PRIORITY_CLASS = $20
#STARTF_USESTDHANDLES = $100
#STARTF_USESHOWWINDOW = $1

;Create the Pipe
sa\nLength =SizeOf(SECURITY_ATTRIBUTES) ;Len(sa)
sa\bInheritHandle = 1
sa\lpSecurityDescriptor = 0
ret = CreatePipe_(@hReadPipe, @hWritePipe, @sa, 0)
If ret = 0
  ;If an error occur during the Pipe creation exit
  MessageRequester("info", "CreatePipe failed. Error: ",0)
  End
EndIf


start\cb = SizeOf(MySTARTUPINFO)
start\dwFlags = #STARTF_USESHOWWINDOW | #STARTF_USESTDHANDLES

;set the StdOutput And the StdError output To the same Write Pipe handle
start\hStdOutput = hWritePipe
start\hStdError = hWritePipe

;Execute the command
ret = CreateProcess_(0, mCommand, sa, sa, 1, #NORMAL_PRIORITY_CLASS, 0, 0, @start, @proc)

If ret <> 1
  MessageRequester("Info","File Or command not found", 0)
  End
Else
  ;MessageRequester("Info","PRG started..:",0)
EndIf


;Now We can ... must close the hWritePipe
ret = CloseHandle_(hWritePipe)

mOutputs.s = ""

;Read the ReadPipe handle
While ret<>0
  ret = ReadFile_(hReadPipe, strBuff, 255, @lngBytesread, 0)
  If lngBytesread>0
    Debug Left(strBuff, lngBytesread)
  EndIf
Wend

;Close the opened handles
ret = CloseHandle_(proc\hProcess)
ret = CloseHandle_(proc\hThread)
ret = CloseHandle_(hReadPipe)
;ret=CloseHandle_(hWritePipe)

Verfasst: 21.05.2009 08:36
von X360 Andy
Cool damit lässt sich was machen (auch wenn ich den Code nicht wirklich ganz kapiere :mrgreen: )