我在 Javascript 中使用 ActiveXObject。
var shell = new ActiveXObject("WScript.Shell");
exec = shell.exec('cmd/c ftp -i -A -s:file.ftp host);
var output = exec.StdOut.ReadAll();
我收到预期错误“无法创建文件”,因为该文件已存在于服务器上。这里一切都好。但是输出不显示 ftp 的错误代码,而 Run 方法会显示 (553 Could not create file)。
我不使用 Run 方法,因为唯一可能的输出是将输出重定向到客户端计算机上的文件中。
相信我,我看了很多网站(包括Windows官方对Run、Exec的说明)
如何使用 WScript.Shell.Exec 命令获取 ftp 命令的错误代码?
更多信息:
exec.StdOut.ReadAll() 输出 ->
"bin
cd my_dir/
mput file_path file_path
Could not create file.
Could not create file.
quit"
WScript.shell.run 的输出文件 ->
ftp> bin
200 Switching to Binary mode.
ftp> cd my_dir/
250 Directory successfully changed.
ftp> mput file_path file_path
200 PORT command successful. Consider using PASV.
553 Could not create file.
200 PORT command successful. Consider using PASV.
553 Could not create file.
ftp> quit
221 Goodbye.
最佳答案
好的,我在一篇 8 年前的帖子中找到了解决方案。 ( http://computer-programming-forum.com/61-wsh/813f07658378176c.htm )
为了使用 Exec 方法从 ftp 命令获得完整的输出,必须将 -v 选项添加到 ftp 命令。 就像一个魅力。
var shell = new ActiveXObject("WScript.Shell");
exec = shell.exec(cmd /c ftp -i -v -A -s:file.ftp host);
var output = exec.StdOut.ReadAll();
关于javascript - Wscript.shell.run 和 Wscript.shell.exec 不显示相同的输出,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18512280/