Pass arguments to a process

Anything beyond the basics in using the LiveCode language. Share your handlers, functions and magic here.

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

Post Reply
dspidell
Posts: 8
Joined: Mon Mar 09, 2020 6:40 pm

Pass arguments to a process

Post by dspidell » Mon Mar 09, 2020 8:12 pm

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.

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 9999
Joined: Wed May 06, 2009 2:28 pm

Re: Pass arguments to a process

Post by dunbarx » Mon Mar 09, 2020 9:44 pm

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

FourthWorld
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 9960
Joined: Sat Apr 08, 2006 7:05 am
Contact:

Re: Pass arguments to a process

Post by FourthWorld » 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.
Richard Gaskin
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn

[-hh]
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 2262
Joined: Thu Feb 28, 2013 11:52 pm

Re: Pass arguments to a process

Post by [-hh] » 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/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 ("&quote&") or by single quotes (') if appropriate,
and you have to remove the "vlc://quit".


Difference: "shell()" is blocking, "open process for neither" not.
shiftLock happens

FourthWorld
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 9960
Joined: Sat Apr 08, 2006 7:05 am
Contact:

Re: Pass arguments to a process

Post by FourthWorld » Mon Mar 09, 2020 11:36 pm

Does VLC continually monitor srdin for inputs beyond the launch params?
Richard Gaskin
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn

[-hh]
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 2262
Joined: Thu Feb 28, 2013 11:52 pm

Re: Pass arguments to a process

Post by [-hh] » Tue Mar 10, 2020 12:02 am

(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/
shiftLock happens

dspidell
Posts: 8
Joined: Mon Mar 09, 2020 6:40 pm

Re: Pass arguments to a process

Post by dspidell » 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.

Thanks.

dspidell
Posts: 8
Joined: Mon Mar 09, 2020 6:40 pm

Re: Pass arguments to a process

Post by dspidell » Wed Mar 11, 2020 5:35 pm

[-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 ("&quote&") 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.

[-hh]
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 2262
Joined: Thu Feb 28, 2013 11:52 pm

Re: Pass arguments to a process

Post by [-hh] » Wed Mar 11, 2020 5:50 pm

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
shiftLock happens

FourthWorld
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 9960
Joined: Sat Apr 08, 2006 7:05 am
Contact:

Re: Pass arguments to a process

Post by FourthWorld » Wed Mar 11, 2020 5:52 pm

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.
Richard Gaskin
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn

dspidell
Posts: 8
Joined: Mon Mar 09, 2020 6:40 pm

Re: Pass arguments to a process

Post by dspidell » Thu Mar 12, 2020 7:14 pm

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.

[-hh]
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 2262
Joined: Thu Feb 28, 2013 11:52 pm

Re: Pass arguments to a process

Post by [-hh] » Thu Mar 12, 2020 7:40 pm

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
Last edited by [-hh] on Thu Mar 12, 2020 9:15 pm, edited 1 time in total.
shiftLock happens

dspidell
Posts: 8
Joined: Mon Mar 09, 2020 6:40 pm

Re: Pass arguments to a process

Post by dspidell » Thu Mar 12, 2020 8:17 pm

Different error:
/bin/sh: line 1: syntax error near unexpected token `&'
/bin/sh: line 1: ` & tCommand & '

[-hh]
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 2262
Joined: Thu Feb 28, 2013 11:52 pm

Re: Pass arguments to a process

Post by [-hh] » Thu Mar 12, 2020 9:02 pm

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)
shiftLock happens

dspidell
Posts: 8
Joined: Mon Mar 09, 2020 6:40 pm

Re: Pass arguments to a process

Post by dspidell » Fri Mar 13, 2020 1:46 pm

Yeah baby! It works.

Thanks you so much. This was a huge hurdle.

Post Reply

Return to “Talking LiveCode”