RunProgram does not produce a result on MacOSX

Just starting out? Need help? Post your questions and find answers here.
Karl-Uwe Frank
User
User
Posts: 17
Joined: Sat Sep 03, 2011 12:33 am

RunProgram does not produce a result on MacOSX

Post by Karl-Uwe Frank »

I'm struggling with getting the result using the following code. In fact it seems to run forever and does not deliver any result at all.

Code: Select all

pid = RunProgram("ls", "-Ramiscut", "/Users/me/Library/Caches/", #PB_Program_Open | #PB_Program_Wait | #PB_Program_Read)
If (pid)
  Define.l BufferSize = AvailableProgramOutput(pid)
  If (BufferSize > 0)
    *Buffer = AllocateMemory(BufferSize)
    ReadProgramData(pid, *Buffer, BufferSize)
    Define.s result = PeekS(*Buffer, BufferSize)
  
    UseMD5Fingerprint()
    PrintN( StringFingerprint(result, #PB_Cipher_MD5) )
    
    FreeMemory(*Buffer)
  EndIf
  CloseProgram(pid)
EndIf
Changing the parameter from "-Ramiscut" to "-rtl" will however produce a result quickly.

Code: Select all

pid = RunProgram("ls", "-rtl", "/Users/me/Library/", #PB_Program_Open | #PB_Program_Wait | #PB_Program_Read)
Perhaps anyone around here having an idea how to solve this problem?

Thanks,
Karl-Uwe
infratec
Always Here
Always Here
Posts: 7581
Joined: Sun Sep 07, 2008 12:45 pm
Location: Germany

Re: RunProgram does not produce a result on MacOSX

Post by infratec »

Hi,

not able to test it yet, but give it a try:

Code: Select all

EnableExplicit

Define.i Received, pid
Define *Buffer
Define Result$, Error$

pid = RunProgram("ls", "-Ramiscut", "/Users/me/Library/Caches/", #PB_Program_Open | #PB_Program_Read | #PB_Program_Error)
If pid
  *Buffer = AllocateMemory(1024)
  If *Buffer
    While(ProgramRunning(pid))
      Received = AvailableProgramOutput(pid)
      If Received
        If ReadProgramData(pid, *Buffer, Received)
          Result$ + PeekS(*Buffer, Received, #PB_UTF8)
        EndIf
      EndIf
      Error$ + ReadProgramError(pid, #PB_UTF8)
    Wend
    Debug "stdout: " + Result$
    Debug "stderr: " + Error$
    UseMD5Fingerprint()
    Debug "MD5: " + StringFingerprint(Result$, #PB_Cipher_MD5)
    FreeMemory(*Buffer)
  EndIf
  CloseProgram(pid)
EndIf
Bernd
Karl-Uwe Frank
User
User
Posts: 17
Joined: Sat Sep 03, 2011 12:33 am

Re: RunProgram does not produce a result on MacOSX

Post by Karl-Uwe Frank »

Hi Bernd,

thanks for you quick reply. Generally spoken your code give me a result, but I experience some malloc error

Code: Select all

./ls-Ramiscut 
ls -Ramiscut: ac363a95f1b69b5609763d7aa68fcfd1
ls-Ramiscut(60676,0x7fff701eacc0) malloc: *** error for object 0x10083b808: incorrect checksum for freed object - object was probably modified after being freed.
*** set a breakpoint in malloc_error_break to debug
Abort trap 
I suppose this is a behaviour that sadly sometimes occur on MacOSX, as others have mentioned in the Forum. Occasionally I get just the desired result without any error, but also once in a while it through a Segmentation fault. Will try to figure out how to change the source code in order to avoid these errors.

Cheers,
Karl-Uwe
Post Reply