gpt4 book ai didi

sql-server-2008 - xp_cmdshell 独立运行 7z,但找不到带参数的 EXE

转载 作者:行者123 更新时间:2023-12-04 06:59:15 25 4
gpt4 key购买 nike

当我如下调用 xp_cmdshell 时,7z.exe 实际运行,并且它的输出是正确的,因为没有包含参数:

declare @Command VARCHAR(1000)
set @Command = '"C:\Program Files\7-Zip\7z.exe" a '
exec master..xp_cmdshell @command
select @Command

输出:

output
NULL
7-Zip 18.05 (x64) : Copyright (c) 1999-2018 Igor Pavlov : 2018-04-30
NULL
NULL
NULL
Command Line Error:
Cannot find archive name
NULL

添加文件后,出现完全不同的错误:未找到 7z.exe:

declare @Command VARCHAR(1000)
set @Command = '"C:\Program Files\7-Zip\7z.exe" a ' + '"' + 'C:\TO_ERASE\ToZip.txt' + '"'
exec master..xp_cmdshell @command
select @Command

输出:

output
'C:\Program' is not recognized as an internal or external command,
operable program or batch file.
NULL

问题是什么?

唯一的区别是我添加了文件名作为参数。如果 7z.exe 生成错误,我会理解,但 Windows 找不到 exe 文件。

最佳答案

有趣的问题。我四处寻找有关文件名中空格的各种解决方案,并遇到了 THIS 。我不确定为什么你的第一个例子有效,但他们的解决方案是在路径之前添加一些东西,这样路径就不是命令中的第一件事。

declare @Command VARCHAR(1000)
set @Command = 'cd.. && "C:\Program Files\7-Zip\7z.exe" a ' + '"' + 'C:\TO_ERASE\ToZip.txt' + '"'
exec master..xp_cmdshell @command
select @Command

关于sql-server-2008 - xp_cmdshell 独立运行 7z,但找不到带参数的 EXE,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50451990/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com