如何修复“'subprocess.CalledProcessError”

时间:2019-04-26 15:41:45

标签: python-2.7 subprocess sys nuke

我正在尝试根据导入文件的位置打开资源管理器。

代码运行,但是打开“ documents”文件夹而不是文件路径。 subprocess.check_call(["explorer", path])。 但是,如果我使用硬编码而不是使用路径变量,则可以得到所需的结果。 在这两种情况下,我都会看到此错误

Traceback (most recent call last):
  File "C:/Program Files/Nuke11.2v4/plugins\nuke\callbacks.py", line 127, in knobChanged
    _doCallbacks(knobChangeds)
  File "C:/Program Files/Nuke11.2v4/plugins\nuke\callbacks.py", line 46, in _doCallbacks
    f[0](*f[1],**f[2])
  File "C:/Users/Nandan/.nuke/python/utilities_v0.1/revealFinder_module\revealFinder.py", line 53, in reveal_finder
    open_folder(path)
  File "C:/Users/Nandan/.nuke/python/utilities_v0.1/revealFinder_module\revealFinder.py", line 78, in open_folder
    subprocess.check_call(["explorer", path])
  File "C:\Program Files\Nuke11.2v4\lib\subprocess.py", line 186, in check_call
    raise CalledProcessError(retcode, cmd)
subprocess.CalledProcessError: Command '['explorer', 'D:/Chrome-Downloads']' returned non-zero exit status 1

我的代码是:

import nuke
import os
import subprocess
import sys


def add_reaveal_button():

    node = nuke.thisNode()
    button_reveal = nuke.PyScript_Knob("revealFinder", "Reveal In Finder ", "")

    # creating a tab inside a node
    tab_custom=nuke.Tab_Knob("custom", "Custom")

    #create a tab and add a button to it
    node.addKnob(tab_custom)
    node.addKnob(button_reveal)


def reveal_finder():
    """
     get file path and reveal src in finder
    :return:none
    """

    node = nuke.thisNode()
    knob = nuke.thisKnob()

    if knob.name() == "revealFinder":

        path = os.path.dirname(node["file"].getValue())

        if os.path.isdir(path):
            print "reveal: "
            print path
            open_folder(path)
        else:
            nuke.message("cant reveal in finder. NMO such dir!")


def open_folder(path):
    """
    reveal path in explorer
    :param path:string path to revel explorer
    :return:none
    """

    #check for mac
    if sys.platform == "darwin":
        subprocess.check_call(["open", path])
    if sys.platform == "linux2":
        subprocess.check_call(["gnome-open", path])
    if sys.platform == "win32":
        subprocess.check_call(["explorer", path])

0 个答案:

没有答案