Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/327.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 如何在fabric.operations.execute中指定env.shell_Python_Fabric - Fatal编程技术网

Python 如何在fabric.operations.execute中指定env.shell

Python 如何在fabric.operations.execute中指定env.shell,python,fabric,Python,Fabric,我使用fabric.tasks.execute在远程服务器上执行命令,并且需要根据系统使用不同的shell。现在我的代码是: def run_test(server_ip, server_shell): execute(test,server_ip,server_shell,host=server_ip) # host can be specified in execute argument def test(ip,shell): env.shell=shell run

我使用fabric.tasks.execute在远程服务器上执行命令,并且需要根据系统使用不同的shell。现在我的代码是:

def run_test(server_ip, server_shell):
    execute(test,server_ip,server_shell,host=server_ip) # host can be specified in execute argument

def test(ip,shell):
    env.shell=shell
    run('command')
我可以接受这一点,但更喜欢执行指定命令将使用的env.shell,而不是在任务中分配它,这非常简单和干净。我可以使用类似于:

def run_test(server_ip, server_shell):
    execute(test,server_ip,server_shell,host=server_ip,*shell=server_shell*) # host can be specified in execute argument

def test(ip,shell):
    run('command')
假设只有
主机
主机
角色
角色
排除主机
关键字参数是特殊的;其余部分按原样传递给任务,即,
shell
传递给
test()

def test(shell):
    with settings(shell=shell):
        run('command')

execute(test, shell=server_shell, host=server_ip)