Page 1 of 1
Pass arguments to a process
Posted: Mon Mar 09, 2020 8:12 pm
by dspidell
Is it possible to pass arguments to a process? For example, in Terminal I can run VLC and pass arguments to create a thumbnail from a video file without opening the VLC interface. The command looks like:
Code: Select all
vlc "myPath/MyVideo" --rate=1 --video-filter=scene -Idummy --vout=dummy --aout=dummy --start-time=10 --stop-time=11 --scene-format=jpg --scene-ratio=24 --scene-prefix=snap --scene-path="DestinationPath" vlc://quit
In LiveCode I can open VLC with:
Code: Select all
Open process "/Applications/VLCdotapp/Contents/MacOS/VLC"
swap "dot" for"."
and I can kill it. I can't seem to find a way to pass the arguments from the Terminal example above to the VLC process. Is it possible?
Thanks.
Re: Pass arguments to a process
Posted: Mon Mar 09, 2020 9:44 pm
by dunbarx
Hi.
Welcome to the forum
I don't see anything in the dictionary entry that supports additional parameters, beyond the native ones, to be passed with the command. Perhaps someone else will have a better reply.
Craig
Re: Pass arguments to a process
Posted: Mon Mar 09, 2020 10:37 pm
by FourthWorld
dspidell, how much experience do you have with inter-process communication? I'm asking because there are several ways to go about it, and which one is best for you will depend on your experience.
Probably the best way to explore the range of options for communicating with a program while it's running is to look for guidance at the vendor's site to see what they offer.
Re: Pass arguments to a process
Posted: Mon Mar 09, 2020 11:16 pm
by [-hh]
The following is generally valid on MacOS and probably on Windows and linux too.
As long as you use full pathes everything that works in terminal will work with LC's shell:
Terminal: /Applications/VLC.app/Contents/MacOS/VLC <args>
LC: put shell("/Applications/VLC.app/Contents/MacOS/VLC <args>")
or use with full pathes:
LC: open process "/Applications/VLC.app/Contents/MacOS/VLC <args>" for neither
With both methods you have to replace quotes (") in args by (""e&") or by single quotes (') if appropriate,
and you have to remove the "vlc://quit".
Difference: "shell()" is blocking, "open process for neither" not.
Re: Pass arguments to a process
Posted: Mon Mar 09, 2020 11:36 pm
by FourthWorld
Does VLC continually monitor srdin for inputs beyond the launch params?
Re: Pass arguments to a process
Posted: Tue Mar 10, 2020 12:02 am
by [-hh]
(This is not related to the OP's question.)
I haven't tried that reading from stdin, but as vlc can stream I think it is possible.
Usually you can also use sockets instead of stdin.
I only use regularly the web interface of vlc for camera-streaming.
Who is interested to work with vlc as cli could start with reading from here
https://wiki.videolan.org/Command-line_interface/
Re: Pass arguments to a process
Posted: Wed Mar 11, 2020 5:29 pm
by dspidell
FourthWorld wrote: ↑Mon Mar 09, 2020 10:37 pm
dspidell, how much experience do you have with inter-process communication? I'm asking because there are several ways to go about it, and which one is best for you will depend on your experience.
Probably the best way to explore the range of options for communicating with a program while it's running is to look for guidance at the vendor's site to see what they offer.
I hove zero experience. I will try some of the other suggestions that have been posted but I would love to hear you r ideas if you know of anythingother than the solutions posted below.
Thanks.
Re: Pass arguments to a process
Posted: Wed Mar 11, 2020 5:35 pm
by dspidell
[-hh] wrote: ↑Mon Mar 09, 2020 11:16 pm
The following is generally valid on MacOS and probably on Windows and linux too.
As long as you use full pathes everything that works in terminal will work with LC's shell:
Terminal: /Applications/VLCdotapp/Contents/MacOS/VLC <args>
LC: put shell("/Applications/VLCdotapp/Contents/MacOS/VLC <args>")
or use with full pathes:
LC: open process "/Applications/VLCdotapp/Contents/MacOS/VLC <args>" for neither
With both methods you have to replace quotes (") in args by (""e&") or by single quotes (') if appropriate,
and you have to remove the "vlc://quit".
Difference: "shell()" is blocking, "open process for neither" not.
I'll try this and let you know how I make out. BTW how do you post to this forum without it complaining about external URls and links regarding the VLCdotapp?
Thanks.
Re: Pass arguments to a process
Posted: Wed Mar 11, 2020 5:50 pm
by [-hh]
I'll try this and let you know how I make out. BTW how do you post to this forum without it complaining about external URls and links regarding the VLCdotapp?
You need more than 10 posts for that. This should really included in the FAQs
https://forums.livecode.com/app.php/help/faq
Re: Pass arguments to a process
Posted: Wed Mar 11, 2020 5:52 pm
by FourthWorld
dspidell wrote: ↑Wed Mar 11, 2020 5:29 pm
FourthWorld wrote: ↑Mon Mar 09, 2020 10:37 pm
dspidell, how much experience do you have with inter-process communication? I'm asking because there are several ways to go about it, and which one is best for you will depend on your experience.
Probably the best way to explore the range of options for communicating with a program while it's running is to look for guidance at the vendor's site to see what they offer.
I hove zero experience. I will try some of the other suggestions that have been posted but I would love to hear you r ideas if you know of anythingother than the solutions posted below.
VLC's command-line reference is here:
https://wiki.videolan.org/Documentation:Command_line/
It's been a while since I look into this, but last time I did I couldn't find anything to do much beyond playing the video. Lots of options for that, but nothing for ongoing interaction between processes via the command line. This is understandable given how stdin works.
VLC does provide deeper hooks, though the libVLC API:
https://wiki.videolan.org/LibVLC/
VLC provides hooks for C++, Java, and others, and a sufficiently-motivated person could use LiveCode Builder for that.
What exactly do you want to do?
dspidell wrote: ↑Wed Mar 11, 2020 5:35 pm
BTW how do you post to this forum without it complaining about external URls and links regarding the VLCdotapp?
It's not just links to Videolan, it's all links.
Like most forums we get tons of spam here. Unlike many, most users don't see it. One of the reasons is that this forum is set up so that new users will need to make at least 10 posts before having the ability to embed live links in their posts.
Trust me. If you saw the stuff us moderators see you'd be very happy with the temporary inconvenience.
Re: Pass arguments to a process
Posted: Thu Mar 12, 2020 7:14 pm
by dspidell
Okay, so this works:
Code: Select all
put shell("/Applications/VLCdotapp/Contents/MacOS/VLC '/Users/me/Pictures/Media Browser/file' --rate=1 --video-filter=scene -Idummy --vout=dummy --aout=dummy --start-time=10 --stop-time=11 --scene-format=jpg --scene-ratio=24 --scene-prefix=snap --scene-path='/Users/me/Desktop' vlc://quit")
I had to leave the "vlc://quit" in or LC would hang until I manually kill the VLC process.
But this:
Code: Select all
put QUOTE & "/Applications/VLCdotapp/Contents/MacOS/VLC '" & tFilePath & "' --rate=1 --video-filter=scene -Idummy --vout=dummy --aout=dummy --start-time=10 --stop-time=11 --scene-format=png --scene-ratio=24 --scene-prefix=snap --scene-path='/Users/me/Desktop' vlc://quit" & QUOTE into tCommand
put Shell(tCommand)
gives this error:
/bin/sh: line 1: /Applications/VLCdotapp/Contents/MacOS/VLC '/Users/me/Pictures/Media Browser/file' --rate=1 --video-filter=scene -Idummy --vout=dummy --aout=dummy --start-time=10 --stop-time=11 --scene-format=png --scene-ratio=24 --scene-prefix=snap --scene-path='/Users/me/Desktop' vlc://quit: No such file or directory
The command looks identical to me. What am I missing?
You asked what I am trying to do. I am trying to iterate through a folder of video files to produce thumbnails so in each loop tFilePath contains the path and filename of a different video.
Thanks.
Re: Pass arguments to a process
Posted: Thu Mar 12, 2020 7:40 pm
by [-hh]
quote & "/Applications..." & quote results in the invalid string ""/Applications..."".
But this should work:
Code: Select all
put "/Applications/VLCdotapp/Contents/MacOS/VLC '" & tFilePath & "'" & \
" --rate=1 --video-filter=scene -Idummy --vout=dummy --aout=dummy" & \
" --start-time=10 --stop-time=11 --scene-format=png --scene-ratio=24" & \
" --scene-prefix=snap --scene-path='/Users/me/Desktop' vlc://quit" into tCommand
-- put Shell(" & tCommand & ") -- is wrong, see below
put Shell(tCommand) -- corrected
Re: Pass arguments to a process
Posted: Thu Mar 12, 2020 8:17 pm
by dspidell
Different error:
/bin/sh: line 1: syntax error near unexpected token `&'
/bin/sh: line 1: ` & tCommand & '
Re: Pass arguments to a process
Posted: Thu Mar 12, 2020 9:02 pm
by [-hh]
Sorry my fault. The quotes are the culprit. This should work:
Code: Select all
put "/Applications/VLCdotapp/Contents/MacOS/VLC '" & tFilePath & "'" & \
" --rate=1 --video-filter=scene -Idummy --vout=dummy --aout=dummy" & \
" --start-time=10 --stop-time=11 --scene-format=png --scene-ratio=24" & \
" --scene-prefix=snap --scene-path='/Users/me/Desktop' vlc://quit" into tCommand
put shell(tCommand)
Re: Pass arguments to a process
Posted: Fri Mar 13, 2020 1:46 pm
by dspidell
Yeah baby! It works.
Thanks you so much. This was a huge hurdle.