我正在制作一个脚本来拍摄照片并将其写入一个用“data&time”创建/命名的文件夹中
我做这个部分是为了创建目录和拍照
pathtoscript = "/home/pi/python-scripts"
current_time = time.localtime()[0:6]
dirfmt = "%4d-%02d-%02d-%02d-%02d-%02d"
dirpath = os.path.join(pathtoscript , dirfmt)
dirname = dirpath % current_time[0:6] #dirname created with date and time
os.mkdir(dirname) #mkdir
pictureName = dirname + "/image%02d.jpg" #path+name of pictures
camera.capture_sequence([pictureName % i for i in range(9)])
然后我想将dirname传递给bash脚本(picturesToServer),后者将图片上传到服务器。 我该怎么做?你知道吗
cmd = '/home/pi/python-scripts/picturesToServer >/dev/null 2>&1 &'
call ([cmd], shell=True)
也许我可以留在python脚本中,将图片scp到服务器上?我有一个带有释义集(ssh add mykey)的ssh代理。你知道吗
通过将
call
替换为:或者将其作为位置参数传递(在脚本的
$1
中可用),方法是将cmd
替换为:作为旁注,在调用子进程时,请考虑使用
shell = True
而不是。使用shell = True
对a lot of reasons that are documented in the Python docs来说是个坏主意相关问题 更多 >
编程相关推荐