Page 1 of 1

RunProgam - tar

Posted: Thu Aug 14, 2025 5:14 pm
by SparrowhawkMMU
Hi,

macOS 15.6, Apple Silicon

I'm trying to get RunProgram to run the following command (filename will vary) which works fine from Terminal (ie a JSON file is extracted and placed in /tmp)

Code: Select all

tar --zstd -xvf "/Users/xxxx/Desktop/vcv/v2/some file name.vcv" -C /tmp/ patch.json
But I get this error:
ERROR: tar: Error opening archive: Can't initialize filter; unable to run program "zstd -d -qq"

Here is my code (apologies, I thought PB editor would convert tabs to spaces and this code is a mixture of new and copied from another of my projects which clearly has different tab settings):

Code: Select all

; given the path to a compressed VCV v2 file, uncompress it and get return the temp file path of
  ; the uncompressed JSON file
Procedure.s GetUncompressedFilePath(compressedFilePath.s, tempFileName.s = #DEFAULT_JSON_FILE_NAME)
    Debug "_FileIndexing::GetDecompressedFilePath()"
  
	  Protected uncompressedPath.s = ""	  
	  Protected tempPath.s = GetTemporaryDirectory()
	  Protected cmd.s = "tar"
	  Protected params.s = "--zstd -xvf " + Chr(34) + compressedFilePath + Chr(34) + " -C " + tempPath + " " + tempFileName
	  
	  uncompressedPath = tempPath + #DIR_SEPARATOR + tempFileName 
	  
	  ; Clear existing file
	  If _FileSystem::FileExists(uncompressedPath)
	    DeleteFile(uncompressedPath)
	  EndIf
	  
 	  Protected error.s = ""
	  Protected programOutput.s = ""
	  
	  Debug "Running terminal: " + cmd + " " + params	  
	  Protected shellProgram.i = RunProgram(cmd, params, "", #PB_Program_Open | #PB_Program_Read | #PB_Program_Error)
	  	  
	  If Not shellProgram
	    uncompressedPath = ""
	  Else
  		While ProgramRunning(shellProgram)  				
   		  error = ReadProgramError(shellProgram)
 			If Not error = ""
 			  uncompressedPath = ""
 				Debug "ERROR: " + error
 			  Break
 			EndIf
  				
			If AvailableProgramOutput(shellProgram)
				programOutput = ReadProgramString(shellProgram)
				Debug "   " + programOutput
			EndIf  				
  		Wend
			
  		Debug "No more output from shell program"
  			
  		CloseProgram(shellProgram)	
  	EndIf
  	
	ExitProc:
	ProcedureReturn uncompressedPath
EndProcedure
Any idea why this would be?

PS. ZStandard is installed via Homebrew

Code: Select all

xxx@xxx  /tmp % which zstd
/opt/homebrew/bin/zstd
xxx@xxx /tmp % zstd --version
*** Zstandard CLI (64-bit) v1.5.7, by Yann Collet ***
PPS. xz is also installed

Re: RunProgam - tar

Posted: Thu Aug 14, 2025 5:21 pm
by Piero

Re: RunProgam - tar

Posted: Thu Aug 14, 2025 8:56 pm
by SparrowhawkMMU
Thanks :)

Re: RunProgam - tar

Posted: Fri Aug 15, 2025 11:18 am
by SparrowhawkMMU
@piero - I'm afraid that I can't get it to work, even when using one of the two shell procs you have on that thread.

When I pass the command to Shell() single quoted, I get:

Code: Select all

Error: /bin/sh: line 1: tar --zstd -xvf "/Users/xxx/Desktop/vcv/v2/test_file_1.vcv" -C /tmp/ patch.json: No such file or directory
The command does not really matter. I tried hard coding ls -l /Users and that gave me the same error.

When I try without the single quotes, I get the same error that I had before:

Code: Select all

Error: tar: Error opening archive: Can't initialize filter; unable to run program "zstd -d -qq"
I wrote a test script with just your code and a simple window to invoke Shell() when a button was clicked. this passed in the hard coded command, to make sure none of my own code was polluting the tests. I sent the command single quoted and not quoted and debugged out the results as above.

Any idea what might be happening?

My "solution" right now is to make this a console app, as obviously tar runs fine in that context. But ideally I'd like a GUI app.

Re: RunProgam - tar

Posted: Tue Aug 19, 2025 10:08 am
by coeddie11
It looks like tar cannot find zstd when launched via RunProgram, so try adding /opt/homebrew/bin explicitly to your PATH in the environment or call tar with --zstd-program=/opt/homebrew/bin/zstd.

Re: RunProgam - tar

Posted: Tue Aug 19, 2025 11:07 am
by Piero
Use a shell procedure this way:

Code: Select all

shell = RunProgram("/bin/zsh", "-l", …
It should (almost exactly) work like Terminal (login Zsh shell; no need for brew paths)…

See here for some more info:
viewtopic.php?p=643139#p643139

Re: RunProgam - tar

Posted: Wed Aug 20, 2025 3:56 pm
by SparrowhawkMMU
Hi, thank you both. Will try these solutions out and let you know how I get on.

Re: RunProgam - tar

Posted: Wed Aug 20, 2025 8:02 pm
by Piero
The only problem you may encounter with my method is that if it doesn't work after successfully testing a "prototype" on Terminal, it VERY probably means that you didn't properly format/quote/escape the "Terminal Command" to a PB string (apropos: see the QuoteString procedure!)
I mean: for complex stuff, remember you can always Debug it… also by pasting it on Terminal:
Image
SparrowhawkMMU wrote: Fri Aug 15, 2025 11:18 am@piero
I tried hard coding ls -l /Users and that gave me the same error
How dare you write such a blasphemy? :x (I'm kidding)

PS/Edit:
Just in case: I noticed you use a "Break" in your code; do you know that CloseProgram does not quit it?