Petit soucis de Process

Vous débutez et vous avez besoin d'aide ? N'hésitez pas à poser vos questions
Avatar de l’utilisateur
flaith
Messages : 1487
Inscription : jeu. 07/avr./2005 1:06
Localisation : Rennes
Contact :

Petit soucis de Process

Message par flaith »

Salut,

j'ai un soucis avec les process, certains fonctionnent d'autres non.

comme c'est plus simple de comprendre avec un prog, le voila :

Code : Tout sélectionner

;/ Created with PureVisionXP v2.13
;/ Fri, 30 Dec 2005 16:33:39
;/ by Nicolas Djurovic

;-Global Variables and Constants
Global hwnd_gadget

;-Window Constants
Enumeration 1
  #Window_Form
EndEnumeration
#WindowIndex=#PB_Compiler_EnumerationValue


;-Gadget Constants
Enumeration 1
  ;Window_Form
  #Gadget_Form_Panel
  #Gadget_Form_Tab_1
  #Gadget_Form_Tab_2
  #Gadget_Form_String
  #Gadget_Form_Text
  #Gadget_Form_Button_compile
  #Gadget_Form_Button_Link
  #Gadget_Form_Button_Run
  #Gadget_Form_Editor_Output
  #Gadget_Form_Button_Quit
  #Gadget_Form_Editor_File
  #Gadget_Form_Button_OK


EndEnumeration
#GadgetIndex=#PB_Compiler_EnumerationValue

Procedure.l Window_Form()
  If OpenWindow(#Window_Form,80,80,740,625,#PB_Window_SystemMenu|#PB_Window_MinimizeGadget|#PB_Window_Invisible,"Compiler Info")
    If CreateGadgetList(WindowID(#Window_Form))
      PanelGadget(#Gadget_Form_Panel,10,10,725,610)
      AddGadgetItem(#Gadget_Form_Panel,-1,"Output")
      hwnd_gadget=EditorGadget(#Gadget_Form_String,5,460,710,120)
        SetGadgetFont(#Gadget_Form_String,LoadFont(#Gadget_Form_String,"Courier New",8,0))
        SendMessage_(hwnd_gadget, #EM_SETTARGETDEVICE, #Null, 0)
        SendMessage_(hwnd_gadget, #EM_SETREADONLY, #True, #Null)              ;On ne peut rien saisir
      TextGadget(#Gadget_Form_Text,5,445,60,15,"Info")
        SetGadgetFont(#Gadget_Form_Text,LoadFont(#Gadget_Form_Text,"",8,0))
      ButtonGadget(#Gadget_Form_Button_compile,655,5,60,40,"Compile")
      ButtonGadget(#Gadget_Form_Button_Link,655,50,60,40,"Link")
      ButtonGadget(#Gadget_Form_Button_Run,655,95,60,40,"Run")
      EditorGadget(#Gadget_Form_Editor_Output,5,5,645,440)
        SetGadgetFont(#Gadget_Form_Editor_Output,LoadFont(#Gadget_Form_Editor_Output,"Courier New",10,0))
      ButtonGadget(#Gadget_Form_Button_Quit,655,185,60,40,"Quit")
      AddGadgetItem(#Gadget_Form_Panel,-1,"File:<>")
      EditorGadget(#Gadget_Form_Editor_File,5,5,710,555)
        SetGadgetFont(#Gadget_Form_Editor_File,LoadFont(#Gadget_Form_Editor_File,"",10,0))
      ButtonGadget(#Gadget_Form_Button_OK,655,565,60,20,"OK")
      CloseGadgetList()
      HideWindow(#Window_Form,0)
      ProcedureReturn WindowID()
    EndIf
  EndIf
EndProcedure

Procedure proc_Do(TheVal.l)
  Select TheVal
    Case 1
      AddGadgetItem(#Gadget_Form_String,-1, "Compiling...")
      AddGadgetItem(#Gadget_Form_String,-1, GetProgramResult("cmd /c type out.asm"))
      Commande.s="fasm out.asm"
      text.s = GetProgramResult(Commande)
      AddGadgetItem(#Gadget_Form_String,-1, text)
    Case 2  
      AddGadgetItem(#Gadget_Form_String,-1, "Linking...")
      Commande.s="ld out.obj libkernel32.a libuser32.a libmsvcrt.a -o out.exe -s --verbose"
      text.s = GetProgramResult(Commande)
      AddGadgetItem(#Gadget_Form_String,-1, text)
    Case 3
      AddGadgetItem(#Gadget_Form_String,-1, "Running...")
      Commande.s="cmd /c out.exe" ; <- PB ICI RIEN NE SE PASSE"dir *.asm *.exe"
      text.s = GetProgramResult(Commande)
      AddGadgetItem(#Gadget_Form_String,-1, text)
  EndSelect
EndProcedure

;-Main Loop
If Window_Form()
  SendMessage_(hwnd_gadget, #EM_SETBKGNDCOLOR, 0, RGB(160,160,160))         ;couleur de fond
  quitForm=0

  Repeat
    EventID  =WaitWindowEvent()
    MenuID   =EventMenuID()
    GadgetID =EventGadgetID()
    WindowID =EventWindowID()

    Select EventID
      Case #PB_Event_CloseWindow
        If WindowID=#Window_Form
          quitForm=1
        EndIf


      Case #PB_Event_Gadget
        Select GadgetID
          Case #Gadget_Form_Tab_1
          Case #Gadget_Form_Tab_2
          Case #Gadget_Form_String
          Case #Gadget_Form_Button_compile
            SetGadgetText(#Gadget_Form_String, "")
            proc_Do(1)
          Case #Gadget_Form_Button_Link
            proc_Do(2)
          Case #Gadget_Form_Button_Run
            proc_Do(3)
          Case #Gadget_Form_Editor_Output
          Case #Gadget_Form_Button_Quit
            quitForm = 1
          Case #Gadget_Form_Editor_File
          Case #Gadget_Form_Button_OK
        EndSelect

    EndSelect
  Until quitForm
  CloseWindow(#Window_Form)
EndIf
End
et le prog ASM :

Code : Tout sélectionner

;*****************************************************************************
; ***** Generated Code "out.asm" - 28/12/05, 00:14:57 - Flaith Gen 0.4
; *****************************************************************************
format  MS COFF

extrn   _ExitProcess@4
extrn   _printf

; *****************************************************************************
; ***** Code
; *****************************************************************************
section '.text' code readable executable

public  _mainCRTStartup

_mainCRTStartup:
	push    _value_print
	call    _printf
	push    0
	call    _ExitProcess@4

; *****************************************************************************
; ***** Data
; *****************************************************************************
section '.data' Data readable writeable

  _value_print     db "---- Test de generation d'un fichier asm",13,10
                   db ">fasm out.asm",13,10
                   db ">ld out.obj libkernel32.a libuser32.a libmsvcrt.a -o out.exe -s",13,10
                   db "---- Si changement de :",13,10
                   db "---- public _mainCRTStartup par _Start, par exemple, faire :",13,10
                   db ">ld -e _Start out.obj libkernel32.a libuser32.a libmsvcrt.a -o out.exe -s",13,10
                   db 0
c'est donc sur la ligne
Commande.s="cmd /c out.exe"
ou rien ne se passe, alors qu'il ne doit afficher que du texte ??? Quelqu'un a une idée du pourquoi ? D'avance merci :)

ps: Il faut la lib de Droopy (merci à lui pour cette lib) :wink:
brossden
Messages : 833
Inscription : lun. 26/janv./2004 14:37

Message par brossden »

Bonjour
il manque pas mal de chose dans ton code comme certaines procedures commr "GetProgramResult"

Code : Tout sélectionner

;/ Created with PureVisionXP v2.13 
;/ Fri, 30 Dec 2005 16:33:39 
;/ by Nicolas Djurovic 
;-Global Variables and Constants 
Global hwnd_gadget 

;-Window Constants 
Enumeration 1 
  #Window_Form 
EndEnumeration 
#WindowIndex=#PB_Compiler_EnumerationValue 


;-Gadget Constants 
Enumeration 1 
  ;Window_Form 
  #Gadget_Form_Panel 
  #Gadget_Form_Tab_1 
  #Gadget_Form_Tab_2 
  #Gadget_Form_String 
  #Gadget_Form_Text 
  #Gadget_Form_Button_compile 
  #Gadget_Form_Button_Link 
  #Gadget_Form_Button_Run 
  #Gadget_Form_Editor_Output 
  #Gadget_Form_Button_Quit 
  #Gadget_Form_Editor_File 
  #Gadget_Form_Button_OK 


EndEnumeration 
#GadgetIndex=#PB_Compiler_EnumerationValue 
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 

Procedure.s ConformationAsciiEtenduVersAscii(Text.s) 
  ReplaceString(Text,Chr(130),"é",2) 
  ReplaceString(Text,Chr(135),"ç",2) 
  ReplaceString(Text,Chr(131),"â",2) 
  ReplaceString(Text,Chr(133),"à",2) 
  ReplaceString(Text,Chr(136),"ê",2) 
  ReplaceString(Text,Chr(137),"ë",2) 
  ReplaceString(Text,Chr(138),"è",2) 
  ReplaceString(Text,Chr(140),"î",2) 
  ReplaceString(Text,Chr(150),"û",2) 
  ReplaceString(Text,Chr(151),"ù",2) 
  ReplaceString(Text,Chr(240),"-",2) 
  ReplaceString(Text,Chr(242),"=",2) 
  ReplaceString(Text,Chr(255)," ",2) 
  
  ; Nettoie des caractères < 31 
  For n=1 To 31 
    If n=9 : Continue : EndIf 
    If n=10 : Continue : EndIf ; LF fout la zone je le supprime 
    ; If n=13 : Continue : EndIf 
    ReplaceString(Text,Chr(n),"",2) 
  Next 
  
  ProcedureReturn Text 
EndProcedure 

Procedure.s GetProgramResult(Command.s) 
  
  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, Command, sa, sa, 1, #NORMAL_PRIORITY_CLASS, 0, 0, @start, @proc) 
  
  If ret <> 1 
    retour.s="" 
  Else 
    
    ;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 
        mOutputs = mOutputs + Left(strBuff, lngBytesread) 
      EndIf 
    Wend 
    
    ;Close the opened handles 
    ret = CloseHandle_(proc\hProcess) 
    ret = CloseHandle_(proc\hThread) 
    ret = CloseHandle_(hReadPipe) 
    ;ret=CloseHandle_(hWritePipe) 
    
    retour.s=mOutputs 
    
  EndIf 
  
  ProcedureReturn ConformationAsciiEtenduVersAscii(mOutputs) 
EndProcedure 

Procedure.l Window_Form() 
  If OpenWindow(#Window_Form,80,80,740,625,#PB_Window_SystemMenu|#PB_Window_MinimizeGadget|#PB_Window_Invisible,"Compiler Info") 
    If CreateGadgetList(WindowID(#Window_Form)) 
      PanelGadget(#Gadget_Form_Panel,10,10,725,610) 
      AddGadgetItem(#Gadget_Form_Panel,-1,"Output") 
      hwnd_gadget=EditorGadget(#Gadget_Form_String,5,460,710,120) 
        SetGadgetFont(#Gadget_Form_String,LoadFont(#Gadget_Form_String,"Courier New",8,0)) 
        SendMessage_(hwnd_gadget, #EM_SETTARGETDEVICE, #Null, 0) 
        SendMessage_(hwnd_gadget, #EM_SETREADONLY, #True, #Null)              ;On ne peut rien saisir 
      TextGadget(#Gadget_Form_Text,5,445,60,15,"Info") 
        SetGadgetFont(#Gadget_Form_Text,LoadFont(#Gadget_Form_Text,"",8,0)) 
      ButtonGadget(#Gadget_Form_Button_compile,655,5,60,40,"Compile") 
      ButtonGadget(#Gadget_Form_Button_Link,655,50,60,40,"Link") 
      ButtonGadget(#Gadget_Form_Button_Run,655,95,60,40,"Run") 
      EditorGadget(#Gadget_Form_Editor_Output,5,5,645,440) 
        SetGadgetFont(#Gadget_Form_Editor_Output,LoadFont(#Gadget_Form_Editor_Output,"Courier New",10,0)) 
      ButtonGadget(#Gadget_Form_Button_Quit,655,185,60,40,"Quit") 
      AddGadgetItem(#Gadget_Form_Panel,-1,"File:<>") 
      EditorGadget(#Gadget_Form_Editor_File,5,5,710,555) 
        SetGadgetFont(#Gadget_Form_Editor_File,LoadFont(#Gadget_Form_Editor_File,"",10,0)) 
      ButtonGadget(#Gadget_Form_Button_OK,655,565,60,20,"OK") 
      CloseGadgetList() 
      HideWindow(#Window_Form,0) 
      ProcedureReturn WindowID() 
    EndIf 
  EndIf 
EndProcedure 

Procedure proc_Do(TheVal.l) 
  Select TheVal 
    Case 1 
      AddGadgetItem(#Gadget_Form_String,-1, "Compiling...") 
      AddGadgetItem(#Gadget_Form_String,-1, GetProgramResult("cmd /c type c:\out.asm")) 
      Commande.s="fasm out.asm" 
      text.s = GetProgramResult(Commande) 
      AddGadgetItem(#Gadget_Form_String,-1, text) 
    Case 2  
      AddGadgetItem(#Gadget_Form_String,-1, "Linking...") 
      Commande.s="ld out.obj libkernel32.a libuser32.a libmsvcrt.a -o out.exe -s --verbose" 
      text.s = GetProgramResult(Commande) 
      AddGadgetItem(#Gadget_Form_String,-1, text) 
    Case 3 
      AddGadgetItem(#Gadget_Form_String,-1, "Running...") 
      Commande.s="cmd /c out.exe" ; <- PB ICI RIEN NE SE PASSE"dir *.asm *.exe" 
      text.s = GetProgramResult(Commande) 
      AddGadgetItem(#Gadget_Form_String,-1, text) 
  EndSelect 
EndProcedure 

;-Main Loop 
If Window_Form() 
  SendMessage_(hwnd_gadget, #EM_SETBKGNDCOLOR, 0, RGB(160,160,160))         ;couleur de fond 
  quitForm=0 

  Repeat 
    EventID  =WaitWindowEvent() 
    MenuID   =EventMenuID() 
    GadgetID =EventGadgetID() 
    WindowID =EventWindowID() 

    Select EventID 
      Case #PB_Event_CloseWindow 
        If WindowID=#Window_Form 
          quitForm=1 
        EndIf 


      Case #PB_Event_Gadget 
        Select GadgetID 
          Case #Gadget_Form_Tab_1 
          Case #Gadget_Form_Tab_2 
          Case #Gadget_Form_String 
          Case #Gadget_Form_Button_compile 
            SetGadgetText(#Gadget_Form_String, "") 
            proc_Do(1) 
          Case #Gadget_Form_Button_Link 
            proc_Do(2) 
          Case #Gadget_Form_Button_Run 
            proc_Do(3) 
          Case #Gadget_Form_Editor_Output 
          Case #Gadget_Form_Button_Quit 
            quitForm = 1 
          Case #Gadget_Form_Editor_File 
          Case #Gadget_Form_Button_OK 
        EndSelect 

    EndSelect 
  Until quitForm 
  CloseWindow(#Window_Form) 
EndIf 
End
Denis

Bonne Jounée à tous
Avatar de l’utilisateur
flaith
Messages : 1487
Inscription : jeu. 07/avr./2005 1:06
Localisation : Rennes
Contact :

Message par flaith »

brossden a écrit :Bonjour
il manque pas mal de chose dans ton code comme certaines procedures commr "GetProgramResult"
Je sais merci, mais elle est dans la lib de Droopy, cf mon petit ps :wink:
Avatar de l’utilisateur
flaith
Messages : 1487
Inscription : jeu. 07/avr./2005 1:06
Localisation : Rennes
Contact :

Message par flaith »

ya personne qui peut aider ou bien ?
Heis Spiter
Messages : 1092
Inscription : mer. 28/janv./2004 16:22
Localisation : 76
Contact :

Message par Heis Spiter »

Bin non, j'ai pas la lib de Droopy... :?
Heis Spiter, webmaster du site http://www.heisspiter.net
Développeur principal et administrateur du projet Bird Chat
Parti courir au bonheur du dév. public et GPL :D
Avatar de l’utilisateur
flaith
Messages : 1487
Inscription : jeu. 07/avr./2005 1:06
Localisation : Rennes
Contact :

Message par flaith »

Brossden (merci à lui) a eu la gentillesse de remplacer la fonction incluse dans la lib de Droopy, donc pas besoin de celle-ci :)
Heis Spiter
Messages : 1092
Inscription : mer. 28/janv./2004 16:22
Localisation : 76
Contact :

Message par Heis Spiter »

T'es commandes MS-DOS sont bizarres.
J'aurais fait :
"cmd /c type c:\out.asm"
"ld out.obj libkernel32.a libuser32.a libmsvcrt.a -o c:\out.exe -s --verbose"
"cmd /c c:\out.exe" (et même pour les puristes "cmd /c call c:\out.exe")

Après, pour plus de mobilité, tu peux faire :
"cmd /c cd C:\ && type out.asm"
"cmd /c cd C:\ && ld out.obj libkernel32.a libuser32.a libmsvcrt.a -o out.exe -s --verbose"
"cmd /c cd C:\ && out.exe" (ou encore une fois "cmd /c cd C:\ && call out.exe"
Il te faudrait tout simplement faire alors

Code : Tout sélectionner

CMD.s = "cmd /c cd C:\ && "
commande.s = CMD.s + "type out.asm"
commande.s = CMD.s + "ld out.obj libkernel32.a libuser32.a libmsvcrt.a -o out.exe -s --verbose"
commande.s = CMD.s + "call out.exe"
D'où la mobilité ;).
Heis Spiter, webmaster du site http://www.heisspiter.net
Développeur principal et administrateur du projet Bird Chat
Parti courir au bonheur du dév. public et GPL :D
Avatar de l’utilisateur
flaith
Messages : 1487
Inscription : jeu. 07/avr./2005 1:06
Localisation : Rennes
Contact :

Message par flaith »

En fait ces commandes en mode console fonctionnent trés bien, mon seul soucis est la récupération des infos du process dans le "#Gadget_Form_String".
Le lancement du "type", du "fasm" et du "ld" affichent bien les résultats attendus, mais pas le programme out.exe, ou la je ne peux pas récupérer les infos.
je sais pas si c'est clair mon truc :lol:
Avatar de l’utilisateur
flaith
Messages : 1487
Inscription : jeu. 07/avr./2005 1:06
Localisation : Rennes
Contact :

Message par flaith »

je cherches toujours et je trouve pas, ya toujours personne qui ... ??? :(
brossden
Messages : 833
Inscription : lun. 26/janv./2004 14:37

Message par brossden »

Faith je pense que personne ne comprend ce que tu veux et le fait que tu nous donnes du code en asm mais pas le compilateur,n'arrange rien si on n'est pas partiquant de la chose alors tente de tout donner plus de billes !
Denis

Bonne Jounée à tous
Avatar de l’utilisateur
flaith
Messages : 1487
Inscription : jeu. 07/avr./2005 1:06
Localisation : Rennes
Contact :

Message par flaith »

brossden a écrit :Faith je pense que personne ne comprend ce que tu veux et le fait que tu nous donnes du code en asm mais pas le compilateur,n'arrange rien si on n'est pas partiquant de la chose alors tente de tout donner plus de billes !
:oops: oops, c'est exact
Fasm est présent dans le rep Compilers de PureBasic, mais pour ld (le linker) il faut avoir installé GCC. Donc le prg out.exe est ICI
voilou !
brossden
Messages : 833
Inscription : lun. 26/janv./2004 14:37

Message par brossden »

Tout fonctionne bien je ne vois pas ce qui te chagrine !

Mais par hasard les fichiers que tu appelles ( "out.asm" "out.exe" ) seraient ils dans un répertoire différent que le répertoire courant de ton application?
Ce qui fait bien evidement que rien ne fonctionnerait dans ce cas là !
Denis

Bonne Jounée à tous
Avatar de l’utilisateur
flaith
Messages : 1487
Inscription : jeu. 07/avr./2005 1:06
Localisation : Rennes
Contact :

Message par flaith »

et bien qd tu lances, dans une console dos, out.exe, il affiche qq lignes de textes, par contre lorsque tu lances le prog purebasic et que tu clic sur le bouton "running", rien ne se passe !!! il ne récupère pas les lignes de textes, enfin chez moi, chez toi ca marche ?
sinon tout est dans le même repertoire !
Merci de ton aide :)
brossden
Messages : 833
Inscription : lun. 26/janv./2004 14:37

Message par brossden »

Oui moi j'obtiens le texte suivant dans la zone d'info en grisé:


Running...
---- Test de generation d'un fichier asm
>fasm out.asm
>ld out.obj libkernel32.a libuser32.a libmsvcrt.a -o out.exe -s
---- Si changement de :
---- public _mainCRTStartup par _Start, par exemple, faire :
>ld -e _Start out.obj libkernel32.a libuser32.a libmsvcrt.a -o out.exe
Denis

Bonne Jounée à tous
Avatar de l’utilisateur
flaith
Messages : 1487
Inscription : jeu. 07/avr./2005 1:06
Localisation : Rennes
Contact :

Message par flaith »

bon et bien voila mon pb Image

de mon côté j'obtiens, dans la zone d'info grisée :
Running...
et c'est tout Image

pour info : W2KSP4
Répondre