Re: Using open process instead of shell

2017-12-25 Thread Mike Bonner via use-livecode
had one more thought to make it easier.  go back to your original idea of
using a shell script but make the script have the format..

#!/bin/sh
[your command here]
echo "Command Complete"

That way, its easy to see when an individual command finishes.

In addition, if you use 3 separate files, 1 for each of your 3 commands,
named logically, you can easily grok which what to do with each.

Finally, for the [your command here] part.. If you want to be able to run
more than 1 at once, if you pass in your arguments as parameters, you don't
have to rewrite the file each time, you just pass in your changeables and
go.

IIRC $0 will contain the name of the shell script any further parameters
will continue in that vein..

For a very simple example, if your shell script named test.sh were to
contain
#!/bin/sh
ls $1
echo
find . |grep $2
echo "Command Complete"

you can run it with--
./test.sh /var barncard

the output would be a listing of the files in folder /var
a space
and a listing of files and folders from the current directory downward that
contain the string barncard.

Should make it easy enough to fire off jobs, multiple if you wish as long
as your parameters differ (so that the open process string is unique)  This
should make it easy to queue up your commands.. Depending on hardware it
might be possible to have 2 or 3 sets (or more?  no clue what hardware you
have) at once.  It would depend on cpu threads and how much load you wanted
to put on things.

Sorry for all the blabbing, had a good day so my thinker is kinda working.

Everyone have a Merry one!
___
use-livecode mailing list
use-livecode@lists.runrev.com
Please visit this url to subscribe, unsubscribe and manage your subscription 
preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode


Re: Using open process instead of shell

2017-12-25 Thread Stephen Barncard via use-livecode
>
>
>  great ideas from Mark Wieder, Mike Bonner, Warren Samples
>
>
​And Glen Bojsza  ! Thanks guys!​
___
use-livecode mailing list
use-livecode@lists.runrev.com
Please visit this url to subscribe, unsubscribe and manage your subscription 
preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode

Re: Using open process instead of shell

2017-12-25 Thread Stephen Barncard via use-livecode
Thank you very much,

 great ideas from Mark Wieder, Mike Bonner, Warren Samples

 I will be working with these  suggestions for the next couple of days and
 report back to you guys.

sqb

--
Stephen Barncard - Sebastopol Ca. USA -
mixstream.org

On Sun, Dec 24, 2017 at 9:10 PM, Warren Samples via use-livecode <
use-livecode@lists.runrev.com> wrote:

> On 12/24/2017 04:05 PM, Stephen Barncard via use-livecode wrote:
>
>> All of the commands work great by using the shell command in LC, except
>> for
>> the fact that my app waits until some of the commands have finished.
>>
>
>
> If your concern is bypassing the blocking nature of shell(), then you
> should be aware that there are methods which detach a process from the
> shell after opening it and these can be used in LiveCode shell() to make it
> non-blocking.
>
> For example:
>
> get shell ("nohup mycommand --some-params 'can use single quotes to escape
> if necessary' &")
>
> here the command is prefaced with the 'nohup' and a space and is closed
> with a space and &
>
>
> There are several variations for redirecting to /dev/null which also work
> to make the shell() non-blocking. Here's an example:
>
> get shell ("mycommand --some-params 'can use single quotes to escape if
> necessary' /dev/null &")
>
>
> This doesn't respond to your direct question about "open process" but it
> *may* be a straightforward way to resolve the issue that has caused you to
> inquire.
>
> Good Luck,
>
> Warren
>
>
> ___
> use-livecode mailing list
> use-livecode@lists.runrev.com
> Please visit this url to subscribe, unsubscribe and manage your
> subscription preferences:
> http://lists.runrev.com/mailman/listinfo/use-livecode
>
___
use-livecode mailing list
use-livecode@lists.runrev.com
Please visit this url to subscribe, unsubscribe and manage your subscription 
preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode


Re: Using open process instead of shell

2017-12-24 Thread Warren Samples via use-livecode

On 12/24/2017 04:05 PM, Stephen Barncard via use-livecode wrote:

All of the commands work great by using the shell command in LC, except for
the fact that my app waits until some of the commands have finished.



If your concern is bypassing the blocking nature of shell(), then you 
should be aware that there are methods which detach a process from the 
shell after opening it and these can be used in LiveCode shell() to make 
it non-blocking.


For example:

get shell ("nohup mycommand --some-params 'can use single quotes to 
escape if necessary' &")


here the command is prefaced with the 'nohup' and a space and is closed 
with a space and &



There are several variations for redirecting to /dev/null which also 
work to make the shell() non-blocking. Here's an example:


get shell ("mycommand --some-params 'can use single quotes to escape if 
necessary' /dev/null &")



This doesn't respond to your direct question about "open process" but it 
*may* be a straightforward way to resolve the issue that has caused you 
to inquire.


Good Luck,

Warren

___
use-livecode mailing list
use-livecode@lists.runrev.com
Please visit this url to subscribe, unsubscribe and manage your subscription 
preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode


Re: Using open process instead of shell

2017-12-24 Thread Mike Bonner via use-livecode
IGnore the "with message" part, had a brain freeze. It would be -- open
process pdata for text read
And then do the -- send "monitorslave pData' to me in 50 millisec -- to
start the loop.

Just tested on linux.  I can start a find process, grab the output of dmesg
and cat a file and direct output to different fields.  But the processes
don't auto close on completion, so you'd have to have a way to recognize
when each finishes based on their output, and close the process. (or if you
don't care about the output, you can
open process tProcess for neither
Which should start a disconnected process that will exit when complete
(assuming its a command that exits on completion)

Another possible method that should make it easy to see when such a process
ends (if you DO want to read the output) would be to open a shell process
for text update.  Then write your command to that shell,  and read the
output.  When it returns to a prompt, its done.

Example code (not using a shell) follows:

local tstarttime
on mouseup

   put empty into field 1
   put empty into field 2
   put empty into field 3

   put the seconds into tstarttime
-- start 3 processes

   put "dmesg" into tProcess1
   put "find /" into tProcess2
   put "cat /etc/fstab" into tProcess3

   open process tProcess1 for text read
   monitorslave tProcess1

   open process tProcess2 for text read
   monitorslave tProcess2

   open process tProcess3 for text read
   monitorslave tProcess3
end mouseup

command monitorSlave pProcess

switch

   case pProcess contains "dmesg"
  read from process pProcess until empty
  put it after field 1
   break

   case pProcess contains "find"
  read from process pProcess until empty
  put it after field 2
   break

   case pProcess contains "cat"
  read from process pProcess until empty
  put it after field 3
   break

end switch

if pProcess is not among the lines of openprocesses() then
 exit "monitorslave"
else
 send "monitorslave pProcess" to me in 100 millisec
end if

-- quick and dirty method of stopping the processes after a minute
-- since this is only testing
if the seconds - tstarttime > 60 then closeProcesses

end monitorSlave

command closeprocesses

   repeat for each line tline in openprocesses()
  close process tLine
   end repeat

end closeprocesses



On Sun, Dec 24, 2017 at 5:56 PM, Mike Bonner  wrote:

> Off the top of my head, untested (no mac available)
>
> on executeProcess pData
> put whereAmI() into a; set the defaultFolder to a
> -- I'd bipass this
> --get "file:xprocess.bat"
> --put pData into URL it
>
>
> open process  "file:xprocess.bat"  for text write
> -- this part, if you want to use a shell file (bat?) you a) have to make
> sure its set to executable
> -- b) You'd want to prepend #!/bin/sh so that it knows what shell to use
> on execution (or use sh xprocess.bat as your command)
> -- c ) Don't think it will work using the URL form  It should be -- open
> process "xprocess.bat" for text read
> -- text read because you want to read the output (or update if you need to
> send additional commands interactive)
>
> --Since you want to be able to check progress you'll need to start a read
> loop too..
> -- if it were me, i'd just call openprocess with your known working
> command line
> open process pData for text read with message
>
> -- start read loop
> send "monitorslave pdata" to me in 50 millisec
>
> close executeProcess
>
>
> command monitorslave pProcess
> -- read loop.. DO what you need to check progress here..
> read from process pProcess until empty
>
> -- Somewhere in here you'll need to determine if the process is done,
> close it, and exit without looping again
> -- or update status and loop again
>
> send monitorslave pProcess to me in 50 millisec -- loop again if not
> done
> end monitorslave
>
>
> if you want to use the same slave loop for multiple processes, you'll of
> course have to parse the url to know how to handle the output
> (Or just make a custom slave loop for each of your 3 executables)
> I also don't know if you will actually need to close the process, or if it
> will self close when done.  As mark pointed out, you can look at
> openprocesses() to see whats currently running.
>
>
>
> On Sun, Dec 24, 2017 at 4:30 PM, Mark Wieder via use-livecode <
> use-livecode@lists.runrev.com> wrote:
>
>> On 12/24/2017 02:05 PM, Stephen Barncard via use-livecode wrote:
>>
>> ​ Does someone out there have a clear example of what I am looking for,
>>> using a UNIX  executable  through *open process​ *?
>>>
>>> 1.call the function  with parameters
>>> 2. allow livecode scripts to continue
>>> 3. continuously monitor and display data returned by that function
>>>
>>>
>>>   thank you all so much for any and all information,
>>>
>>
>> check out the openProcesses function to see what's still in play
>> here's an example from the 'close process' doc:
>>
>> close process myProcess
>> wait until myProcess 

Re: Using open process instead of shell

2017-12-24 Thread Mike Bonner via use-livecode
Off the top of my head, untested (no mac available)

on executeProcess pData
put whereAmI() into a; set the defaultFolder to a
-- I'd bipass this
--get "file:xprocess.bat"
--put pData into URL it


open process  "file:xprocess.bat"  for text write
-- this part, if you want to use a shell file (bat?) you a) have to make
sure its set to executable
-- b) You'd want to prepend #!/bin/sh so that it knows what shell to use on
execution (or use sh xprocess.bat as your command)
-- c ) Don't think it will work using the URL form  It should be -- open
process "xprocess.bat" for text read
-- text read because you want to read the output (or update if you need to
send additional commands interactive)

--Since you want to be able to check progress you'll need to start a read
loop too..
-- if it were me, i'd just call openprocess with your known working command
line
open process pData for text read with message

-- start read loop
send "monitorslave pdata" to me in 50 millisec

close executeProcess


command monitorslave pProcess
-- read loop.. DO what you need to check progress here..
read from process pProcess until empty

-- Somewhere in here you'll need to determine if the process is done, close
it, and exit without looping again
-- or update status and loop again

send monitorslave pProcess to me in 50 millisec -- loop again if not
done
end monitorslave


if you want to use the same slave loop for multiple processes, you'll of
course have to parse the url to know how to handle the output
(Or just make a custom slave loop for each of your 3 executables)
I also don't know if you will actually need to close the process, or if it
will self close when done.  As mark pointed out, you can look at
openprocesses() to see whats currently running.



On Sun, Dec 24, 2017 at 4:30 PM, Mark Wieder via use-livecode <
use-livecode@lists.runrev.com> wrote:

> On 12/24/2017 02:05 PM, Stephen Barncard via use-livecode wrote:
>
> ​ Does someone out there have a clear example of what I am looking for,
>> using a UNIX  executable  through *open process​ *?
>>
>> 1.call the function  with parameters
>> 2. allow livecode scripts to continue
>> 3. continuously monitor and display data returned by that function
>>
>>
>>   thank you all so much for any and all information,
>>
>
> check out the openProcesses function to see what's still in play
> here's an example from the 'close process' doc:
>
> close process myProcess
> wait until myProcess is not among the lines of the openProcesses
> open process myProcess
>
>
> --
>  Mark Wieder
>  ahsoftw...@gmail.com
>
>
> ___
> use-livecode mailing list
> use-livecode@lists.runrev.com
> Please visit this url to subscribe, unsubscribe and manage your
> subscription preferences:
> http://lists.runrev.com/mailman/listinfo/use-livecode
>
___
use-livecode mailing list
use-livecode@lists.runrev.com
Please visit this url to subscribe, unsubscribe and manage your subscription 
preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode

Re: Using open process instead of shell

2017-12-24 Thread Mark Wieder via use-livecode

On 12/24/2017 02:05 PM, Stephen Barncard via use-livecode wrote:


​ Does someone out there have a clear example of what I am looking for,
using a UNIX  executable  through *open process​ *?

1.call the function  with parameters
2. allow livecode scripts to continue
3. continuously monitor and display data returned by that function


  thank you all so much for any and all information,


check out the openProcesses function to see what's still in play
here's an example from the 'close process' doc:

close process myProcess
wait until myProcess is not among the lines of the openProcesses
open process myProcess


--
 Mark Wieder
 ahsoftw...@gmail.com

___
use-livecode mailing list
use-livecode@lists.runrev.com
Please visit this url to subscribe, unsubscribe and manage your subscription 
preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode

Using open process instead of shell

2017-12-24 Thread Stephen Barncard via use-livecode
Hi gang, I need a little help here.

I am creating a Macintosh app on the desktop for my own use.
 I am making an archive of all the "Spirit of K JAZ"   shows by the late
Jerry Dean.After the terrestrial radio station went off the air,  he
and fellow air mate Stan Dunn started streaming the shows on the net for
most of the 2000 decade.  There are over 800  1-hour shows in this
collection.
 After archiving the first 200 shows,  I quickly tired of using individual
apps to do the separate steps of photographing the cover, putting in
folder, and transferring the data, while keeping the same file name for all
of them.   So I created a stack which controls several  command line
executables

 I have three executable binaries that I  call from this app.

imagesnap
ffmpeg
SOX

All of the commands work great by using the shell command in LC, except for
the fact that my app waits until some of the commands have finished.
In the case of one of them  for example, it is importing a audio file from
a CD, and turning it into a wave file using *ffmpeg*.

./ffmpeg -i '/Volumes/Audio CD/1 Audio Track.aiff'
'/Users/stephenbarncard/Desktop/img/20171113_LIVE_ON_MARz.wav'


[ above  command on one line ]


This takes up to 10 minutes to copy for a 60 minute CD.
​
​The  ./​  at the beginning is the only difference between what I was
saying in my shell call from LC  and what works in Terminal.

The executables live directly adjacent to the live code stack, to simplify
addressing.   I got about this far with my coding, reading stuff from
forums and the dictionary, but I just can't seem to put the right words
together.

pData  is the command that works from the shell.

on executeProcess pData

put whereAmI() into a; set the defaultFolder to a

get "file:xprocess.bat"

put pData into URL it

open process  "file:xprocess.bat"  for text write

etc..

close executeProcess


​ Does someone out there have a clear example of what I am looking for,
using a UNIX  executable  through *open process​ *?

1.call the function  with parameters
2. allow livecode scripts to continue
3. continuously monitor and display data returned by that function


 thank you all so much for any and all information,

And a happy  non-sectarian Christmas to everyone!









*Stephen Barncard - Sebastopol Ca. USA - *
*mixstream.org* 
___
use-livecode mailing list
use-livecode@lists.runrev.com
Please visit this url to subscribe, unsubscribe and manage your subscription 
preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode