我在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();
我得到预期的错误“无法创build文件”,因为该文件已经存在于服务器上。 这里一切正常。 但是输出不显示ftp的错误代码 ,而Run方法却不显示(553无法创build文件)。
我不使用Run方法,因为唯一可能的输出是将输出redirect到客户机上的文件。
相信我,我读了很多网站(包括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();