problem with SHELL

Post your Gambas programming questions here.
Post Reply
bill-lancaster
Posts: 195
Joined: Tuesday 26th September 2017 3:17pm
Location: NW England

problem with SHELL

Post by bill-lancaster »

I wish to display audio metadata contained in audio files in a folder.

Using ffprobe in a shell command.

Code: Select all

Shell "ffprobe " & PathToAudioFile 
Shows the metadata in the IDE console

Code: Select all

Shell "ffprobe " & PathToAudioFile TO sVar 
Produces an empty string

Code: Select all

Shell "ffprobe " & PathToAudioFile For Read As "Process" 
Does not invoke Process_Read()

I must be making a simple mistake here but I can't see it. Any help would be welcome.
User avatar
cogier
Site Admin
Posts: 1125
Joined: Wednesday 21st September 2016 2:22pm
Location: Guernsey, Channel Islands

Re: problem with SHELL

Post by cogier »

Hi Bill, I have no idea why you can't use 'process' but I can't see the need. I suggest you try the excellent 'exiftool' to do this. I have knocked together the attached program that will pull out the details, if they are there!

NOTE: - You need to install 'exiftool'. The good part is that you can add the 'exiftool' to your own program as I did with my program PhotoExif.

Image
MusicEXIF-0.0.1.tar.gz
(12 KiB) Downloaded 270 times
bill-lancaster
Posts: 195
Joined: Tuesday 26th September 2017 3:17pm
Location: NW England

Re: problem with SHELL

Post by bill-lancaster »

Thank you for the excellent code but it doesn't work for me. There is something strange with my system.
The line:-

Code: Select all

Shell "exiftool " & User.Home &/ "Music/recordings" &/ "'" & GridViewTracks[Last.Row, 0].text & "'" To sData
yields an empty string.

I'm running Gambas 3.15.1 in Kubuntu 20.04

I'll try to find out why my system is mis-behaving.

Thanks again
User avatar
stevedee
Posts: 518
Joined: Monday 20th March 2017 6:06pm

Re: problem with SHELL

Post by stevedee »

bill-lancaster wrote: Saturday 19th September 2020 6:37pm ...I'll try to find out why my system is mis-behaving...
Hi Bill, your variable is probably empty because the process does not complete before your code proceeds to the next step. You may be able to prove this by single stepping through your code in the IDE.

If this is the case, rewrite the Shell command using the Wait keyword.
User avatar
BruceSteers
Posts: 1570
Joined: Thursday 23rd July 2020 5:20pm
Location: Isle of Wight
Contact:

Re: problem with SHELL

Post by BruceSteers »

ffprobe has some fancy text output formatting
You could do it with redirecting the output in the command and reading in the file...
(dont forget the 'Wait' arg or you might miss the output :))

Code: Select all

Shell "ffprobe " & Quote(PathToAudioFile) & " 2>/tmp/ffoutput" Wait
sVar = File.Load("/tmp/ffoutput")
Kill "/tmp/ffoutput"
If at first you don't succeed , try doing something differently.
BruceS
bill-lancaster
Posts: 195
Joined: Tuesday 26th September 2017 3:17pm
Location: NW England

Re: problem with SHELL

Post by bill-lancaster »

cogier's programme didn't work first time because, stupidly, I hadn't installed exiftool!

Thanks also for suggesting the use of WAIT.

I still get a null string when using ffprobe or ffmpeg. If I print the shell command, copy it and run it in console it works. Doesn't make sense.

Anyway, exiftool does the job (probably better) so I'll move on.

Small point, splitting each line of the exiftool output based on the first ":" preserves the format of date/time values, otherwise for example Duration is shown as "3" instead of "3:30:00".

Thanks for all the ideas.
User avatar
BruceSteers
Posts: 1570
Joined: Thursday 23rd July 2020 5:20pm
Location: Isle of Wight
Contact:

Re: problem with SHELL

Post by BruceSteers »

I still get a null string when using ffprobe or ffmpeg. If I print the shell command, copy it and run it in console it works. Doesn't make sense.
Yeah ffprobe and ffmpeg output in a non standard way. redirecting 2> often works for that.
If at first you don't succeed , try doing something differently.
BruceS
User avatar
cogier
Site Admin
Posts: 1125
Joined: Wednesday 21st September 2016 2:22pm
Location: Guernsey, Channel Islands

Re: problem with SHELL

Post by cogier »

Just one point about using WAIT. There is no need to use it if you are collecting the data in a variable as Gambas will always wait so that it can fill the variable.
User avatar
BruceSteers
Posts: 1570
Joined: Thursday 23rd July 2020 5:20pm
Location: Isle of Wight
Contact:

Re: problem with SHELL

Post by BruceSteers »

I just found this code reading through the wiki Shell info and thought i'd try it out on this scenario.
Only the standard output of the process is retrieved. The error output is not redirected.
If you need to mix both output, use the shell redirection syntax:
Shell "command 2>&1" To Result
I tried it and

Code: Select all

Shell "ffprobe " & Quote(filename) & " 2>&1" Wait To mString
DID fill mString with the output.

A bit late for the solution there I guess but that lil bit of info could help someone else in a similar situation i think.
If at first you don't succeed , try doing something differently.
BruceS
Post Reply