![](/img/trans.png)
[英]Installing gphoto2 on mac os x Yosemite - issue with ./configure
[英]get current status of gphoto2
我运行带有--wait-event-and-download参数的gphoto,以便将使用红外遥控器拍摄的照片保存到计算机中。
我设置了第二个脚本来中断等待过程并以编程方式拍摄照片,如下所示:
#!/bin/sh
# shootnow.sh - stop the current gphoto2 process (if it exists),
# shoot a new image, then start a new wait-event process.
pkill -INT gphoto2 #send interrupt (i.e. ctrl+c) to gphoto2
sleep 0.1 #avoid the process ownership error
gphoto2 --capture-image-and-download #take a picture now
gphoto2 --wait-event-and-download #start a new wait-event process
但是我想确保在中断之前,当前的第一个等待事件过程没有下载图像(这会导致混乱的情况,即图像填满了相机的内存,从而阻止了进一步的操作)。 所以第二个脚本应该更像这样:
#!/bin/sh
# shootnow-with-check.sh - stop the current gphoto2 process (if it exists
# and isn't currently downloading an image), shoot a new image, then start
# a new wait-event process.
shootnow() { # same as previously, but now in a function
pkill -INT gphoto2
sleep 0.1
gphoto2 --capture-image-and-download
gphoto2 --wait-event-and-download
}
if [ ***current output line of gphoto2 process doesnt start with "Downloading"*** ] then
shootnow
else
echo "Capture aborted - a picture was just taken and is being saved."
fi
如果声明,有人可以帮我吗? 我可以读取正在运行的gphoto进程的当前输出行吗?
我最终使用如下脚本来管理:
#!/bin/bash
# gphoto2-expect.sh
# use expect to monitor gphoto2 during --capture-image-and-download with
# --interval=-1, adding in SIGUSR1 functionality except during a
# download event.
echo "Prepping system for camera"
killall PTPCamera
expect << 'EOS'
puts "Starting capture..."
if [catch "spawn gphoto2 --capture-image-and-download --interval=-1" gp_pid] {
Log $ERROR "Unable to start gphoto2.\n$gp_pid\n"
return 0
}
trap {exec kill -SIGUSR1 $gp_pid} SIGUSR1
set timeout -1
expect {
-i $spawn_id
"Downloading" {
trap {send_user "\n Ignoring request as currently downloading"} SIGUSR1 ; exp_continue
}
"Saving file as" {
sleep 0.1
trap {exec kill -SIGUSR1 $gp_pid} SIGUSR1 ; exp_continue
}
}
EOS
可以用另一个脚本触发:
#!/bin/bash
# trigger.sh - trigger an immediate capture
var=$(pidof expect)
kill -SIGUSR1 "$var"
gphoto2有一个选项--hook-script FILENAME。 FILENAME必须是一个可执行脚本,并在某些gphoto2事件上被调用。 然后,脚本具有一个环境变量ACTION,您可以将其用于您的目的。 例如:您使用以下命令调用gphoto2
gphoto2 --capture-image-and-download --hook-script myhook.sh
和myhook.sh看起来像
#! /bin/bash
echo $ACTION
那么myhook.sh将被调用4次。 它的输出是
init
start
download
stop
有关详细信息,请参见man gphoto2。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.