如果>操作系统(文件路径)备选

2024-09-30 16:40:01 发布

您现在位置:Python中文网/ 问答频道 /正文

我遇到了一个问题,因为在我的Python代码中os.system(filePath)将执行,但代码将停止,直到我手动关闭打开的PDF文件的窗口。你知道吗

我想打开一个PDF文件使用openCV来捕获我的屏幕从而捕获文件的图像。如果代码没有在我关闭窗口的情况下运行,这将成为一个问题。。。你知道吗

代码:

import numpy as np
import shutil,os, cv2, SendKeys, win32com.client

#While our In File has stuff in it
while(os.listdir(pathForInFile)!=[]):
    for subdir, dirs, inFile in os.walk(pathForInFile):
        for fileName in inFile:
            filePath= subdir+os.sep+fileName

            os.system(filePath)

            print "THIS WILL RUN NOT UNTIL I CLOSE FILE"

            shell.SendKeys('{DOWN}')

Tags: 文件代码inimportforpdfos手动
1条回答
网友
1楼 · 发布于 2024-09-30 16:40:01

您可以在Windows 8.1(在虚拟机中测试)上使用此解决方案:

import os
os.system('start path_to_my_filename.pdf')
print("You do not need to close the opened PDF file to run and see this")

和Ubuntu(14.04.4 LTS):

import os
# f = /home/begueradj/Desktop/metasploitBible.pdf'
os.system('xdg-open path_to_my_filename.pdf')
print("You do not need to close the opened PDF file to run and see this")

相关问题 更多 >