如何将输出从CMD窗口重定向到文件 [英] How to redirect output from CMD window to file
本文介绍了如何将输出从CMD窗口重定向到文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我编写了以下VBScript,以便在Linux计算机上从WIN XP运行命令并将输出命令重定向到out.txt
文件(在C:\
下)
I wrote the following VBScript in order to run commands from WIN XP on a Linux machine and redirect the output command to out.txt
file (under C:\
)
我不明白为什么命令窗口中的输出未写入out.txt
文件.
I don’t understand why output from the command window is not written to out.txt
file.
该行有什么问题
Sh.Run "cmd /k & CMD >> ""C:\out.txt""" , 1, True
我的完整VB脚本:
'TARGET_HOST - Linux machine
Const TARGET_HOST = "18.20.183.99"
const PATH = "cat /etc/hosts"
const LOGIN = "root"
const PASS = " dingdong "
Const PLINKPATH="""C:\SPUTNIK\plink.exe"""
Set Sh = CreateObject("WScript.Shell")
CMD = " echo y | " & PLINKPATH & " -ssh -pw " & PASS & LOGIN & "@" & " " & TARGET_HOST & " " & PATH
Sh.Run "cmd /k & CMD >> ""C:\out.txt""" , 1, True
Set Sh = Nothing
推荐答案
VBScript不会在字符串内部扩展变量.更改此:
VBScript doesn't expand variables inside strings. Change this:
Sh.Run "cmd /k & CMD >> ""C:\out.txt""" , 1, True
对此:
Sh.Run "cmd /k " & CMD & " >> ""C:\out.txt""" , 1, True
最重要的是,您的命令格式错误.您需要在密码和用户名之间放置一个空格,并删除@
和主机名之间的空格:
On top of that your command is malformed. You need to put a space between password and username, and remove the space between @
and hostname:
CMD = " echo y | " & PLINKPATH & " -ssh -pw " & PASS & " " _
& LOGIN & "@" & TARGET_HOST & " " & PATH
这篇关于如何将输出从CMD窗口重定向到文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文