2014-02-23 39 views
0

这是代码,我遇到的问题是,尽管一切按预期工作,除非指定完整的文件路径(如在“s”中),否则不能调用所需的perl脚本。 ,即使它们都在同一个目录(桌面)中。任何帮助,将不胜感激。从python调用perl没有完整的文件路径

import subprocess 
status = ['s', 'mj', 'ms', 'h','q'] 
while(1): 
    while(1): 
     print("Compute income tax: \n") 
     print("\ts = single \n") 
     print("\tmj = married and filing jointly \n") 
     print("\tms = married and filing seperately \n") 
     print("\th = head of household \n") 
     print("\tq = quit \n") 
     #get user input for status 
     choice=raw_input("Enter status: ") 
     if (choice in status): 
      print("58") 
      break 
     else: 
      print("Unknown status!") 
    if (choice=='q'): 
     break 
    else: 
     if (choice=="s"): 
      subprocess.call('perl C:/Users/Username/Desktop/single.pl') 
     elif(choice=='mj'): 
      subprocess.call('perl marriedJointly.pl') 
     elif(choice=='ms'): 
      subprocess.call('perl marriedSeperately.pl') 
     elif(choice=='h'): 
      subprocess.call('perl head.pl') 
      #and so on 

回答

0

您是否正在调用像C:\>python myscript.py这样的脚本?如果是这样,那么你的脚本实际上将在python程序下运行,这意味着它的位置将在python可执行文件的位置,而不是脚本。您可以通过导入os并运行os.getcwd()来验证此问题,这可能会显示类似'C:\\Python33'的内容。

为了解决这个问题,无论是直接通过做C:\myscript.py调用脚本(该工程只是finel;的Windows知道使用基于断扩展其解释器),使用os.chdir()以修复文件系统中的位置,或者只是使用绝对寻路。

+0

呃,不,我打开命令提示符窗口并输入完整的文件路径并执行它。我打开cmd并将文件拖到窗口中,然后按回车。 – user2167980

+0

哦,明白了,这是其他文件的问题,谢谢你的帮助。 – user2167980