I am interested in using FB to start an external program, let it run for 100 seconds and then stopping it. I have found the run command, but it stops fb and waits for the program to stop itself. Is there any way to issue a command to kill the external program after a certain amount of running time?
Thanks,
John
Stopping an external program
-
- Posts: 43
- Joined: Jun 21, 2016 13:06
Re: Stopping an external program
If you are on Linux I think you should just run killall: https://www.linux.com/topic/desktop/how ... mand-line/Helium5793 wrote:I am interested in using FB to start an external program, let it run for 100 seconds and then stopping it. I have found the run command, but it stops fb and waits for the program to stop itself. Is there any way to issue a command to kill the external program after a certain amount of running time?
Thanks,
John
Re: Stopping an external program
Windows
Code: Select all
shell "start notepad "
dim as double t=timer
do
locate 5
print "Notepad for five seconds"
if timer-t>5 then
shell "taskkill /F /IM notepad.exe"
exit do
end if
loop
sleep
-
- Posts: 43
- Joined: Jun 21, 2016 13:06
Re: Stopping an external program
Thank you for your responses. I am under linux, and last night I did find a solution. The program I am running is designed to use an arduino with sensors and a terminal program to take data on the moon. I needed the program to wait some time, then run coolterm, collect data for some time, and then shut coolterm down. The linux command I found to do it (killall might well be a good alternative) was 'timeout'. It allows you to set how long to run the program. I have attached my code, the program is named coolterm_control.bas. It would be useful for anyone wanting to run a program under linux at a later time unattended.
Code: Select all
/'
timeout
DURATION is a floating point number with an optional suffix:
's' for seconds (the default), 'm' for minutes, 'h' for hours or 'd' for days.
A duration of 0 disables the associated timeout.
'/
declare sub twovlbox()
dim shared as integer result
dim shared as single hrs_til_start
dim shared as single minutes_to_run,wait_for_it
dim shared as integer black = 0, blue = 1, green = 2, cyan = 3, red = 4
dim shared as integer magenta = 5, brown = 6, white = 7,grey = 8
dim shared as integer bright_blue = 9, bright_green = 10, bright_cyan = 11
dim shared as integer bright_red = 12, bright_magenta = 13, yellow = 14
dim shared as integer bright_white = 15
dim shared as integer center,MaxCol,Tcol,x,i
dim shared as integer Tcolor, mode,lcol, rcol, trow, brow, fore, back
dim shared as string set_command
SCREEN 9
COLOR white, blue
CLS
lcol=4:rcol= 75:trow= 1:brow= 6:fore=white:back= blue
twovlbox()
COLOR yellow, blue
LOCATE 2, 32: PRINT "CoolTerm Controller"
COLOR white, blue
LOCATE 3, 30: PRINT "Sets up a coolterm run"
LOCATE 8, 5
input "Hours until start (zB 2.5)";hrs_til_start
input "Minutes to run (zB 480)";minutes_to_run
sleep hrs_til_start*3600*1000
set_command= " "+str(minutes_to_run)+ "m ./CoolTerm"
print time
result = exec ("timeout", set_command)
print time
sleep
SUB twovlbox ()
COLOR fore, back: LOCATE trow, lcol
X = rcol - lcol - 1
PRINT CHR(214); STRING(X, CHR(196)); CHR(183);
FOR i = (trow + 1) TO (brow - 1)
LOCATE i, lcol
PRINT CHR(186); STRING(X, " "); CHR(186);
NEXT i
LOCATE brow, lcol
PRINT CHR(211); STRING(X, CHR(196)); CHR(189);
END SUB