如何将Shell命令的输出保存到VBA中的文本文件中 [英] How to save the ouput of shell command into a text file in VBA
问题描述
我的代码是这样写的,
function ftpsend()
Dim vPath As String
Dim vFile As String
Dim vFTPServ As String
Dim fNum As Long
Dim currntdir As String
currntdir = ThisWorkbook.Path & "\"
vPath = currntdir
vFile = currntdir & "abc.xml"
vFTPServ = "ftp.abc.com"
'Mounting file command for ftp.exe
fNum = FreeFile()
Open vPath & "abc.txt" For Output As #fNum
Print #1, "USER student"
Print #1, "xxxxx"
Print #1, "send " & vFile
Print #1, "close"
Print #1, "quit"
Close
Shell "ftp -n -i -g -s:" & vPath & "abc.txt " & vFTPServ, vbNormalFocus
end function
现在,shell命令在控制台ftp.exe中将输出显示为
Now, the shell command displays the output in the console ftp.exe as
Connected to ftp.abc.com
220 Microsoft FTP service
ftp>USER student
230 User logged in
ftp>send D:abc.xml
200 PORT command successful
226 Transfer Complete
ftp>close
221>Good bye
ftp>
我希望将控制台的输出复制到文本文件中.因为,有时用户名和密码不正确,它会在控制台中显示消息用户未登录",登录失败".想处理该错误.还有其他处理ftp错误的方法吗?请帮忙...
I want this output from console as it is copied into a text file.Because,sometimes when the username and password are incorrect, it displays the message as " User not logged in ", "Login failed" in the console.I want to handle that error.Any other way to handle ftp errors? Please Help...
预先感谢
推荐答案
尝试替换
Shell "ftp -n -i -g -s:" & vPath & "abc.txt " & vFTPServ, vbNormalFocus
作者
Shell "ftp -n -i -g -s:" & vPath & "abc.txt " & vFTPServ & " > test.txt", vbNormalFocus
或
Shell "ftp -n -i -g -s:" & vPath & "abc.txt " & vFTPServ & " >> test.txt", vbNormalFocus
>
或>>
将控制台输出转移到文件.如果>
和>>
不存在,都将创建test.txt
. >
将删除现有的text.txt,而>>
会将新输出附加到test.txt
的现有内容.
>
or >>
diverts console output to a file. Both >
and >>
will create test.txt
if it does not exist. >
will delete an existing text.txt while >>
will append the new output to the existing contents of test.txt
.
这篇关于如何将Shell命令的输出保存到VBA中的文本文件中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!