Python 带有多个文件的paramiko ls输出被截断
我在ls中成功地使用了paramiko的exec_命令,直到我尝试将文件列表作为参数。我的职能是:Python 带有多个文件的paramiko ls输出被截断,python,bash,python-3.x,paramiko,ls,Python,Bash,Python 3.x,Paramiko,Ls,我在ls中成功地使用了paramiko的exec_命令,直到我尝试将文件列表作为参数。我的职能是: def jz_orion_ssh_sout_list(cmd): with paramiko.SSHClient() as ssh: ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy()) ssh.connect(orion['host'], username=orion['username'],
def jz_orion_ssh_sout_list(cmd):
with paramiko.SSHClient() as ssh:
ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
ssh.connect(orion['host'], username=orion['username'], password=orion['password'])
ssh_stdin, ssh_stdout, ssh_stderr = ssh.exec_command(cmd)
sout = ssh_stdout.readlines()
serr = ssh_stderr.readlines()
return sout
当cmd='ls-l/my/path/file.txt'
工作正常时,但当cmd='ls-l/my/path/file1.txt file2.txt file3.txt'
时,它只返回file1.txt。直接在目标服务器上运行后一个cmd将返回所有3个文件
如何让它在帕拉米科工作
另外,我发现了另一种在paramiko中有效的语法:
cmd='ls-l/my/path/{file1.txt,file2.txt,file3.txt}
,但我仍然想知道是什么原因导致了前面提到的语法的失败。这是你的cmd
问题:
例如,我在示例文件夹下有3个文件:
➜ ls example
file1 file2 file4
找不到文件2:
➜ ls -l example/file1 file2
ls: file2: No such file or directory
-rw-r--r-- 1 haifzhan staff 391 28 Nov 10:23 example/file1
ls-l示例/file1 file2
说明ls
file2位于当前目录下,而不是文件夹示例下
如果我们只为file1和file2运行命令
➜ ls -l example/file[1-2]
-rw-r--r-- 1 haifzhan staff 391 28 Nov 10:23 example/file1
-rw-r--r-- 1 haifzhan staff 81 28 Nov 10:26 example/file2
或者:
ls -l example/file1 example/file2
-rw-r--r-- 1 haifzhan staff 391 28 Nov 10:23 example/file1
-rw-r--r-- 1 haifzhan staff 81 28 Nov 10:26 example/file2
在你的例子中,
ls-l/my/path/{file1.txt,file2.txt,file3.txt}
的作用是你告诉ls
你的所有文件都在/my/path
为什么不使用ls-l/my/path/file[1-3].txt?