VBSでDOSコマンドを実行したいと考えています。
リダイレクトを使って実行を試みましたが、上手くいきません。
もともと、VBSでDOSコマンドを実行すること自体が無理なんでしょうか?
とりあえず、試して駄目だったものは次のとおりです。
VBSでDOSコマンドを実行する方法をご存知でしたら教えてください。
WS.Run "C:\WINNT\system32\netsh.exe -c interface dump > C:\TEMP\red_network.txt
WS.Run "command.com netsh.exe -c interface dump > C:\TEMP\red_network.txt"
'WS.Run "C:\WINNT\system32\command.com > C:\WINNT\system32\netsh.exe -c interface dump > C:\TEMP\red_network.txt"
WS.Run "C:\WINNT\system32\command.com < netsh -c interface dump > C:\TEMP\red_network.txt"
WS.Run "C:\WINNT\system32\command.com > netsh -c interface dump > C:\TEMP\red_network.txt"
WS.Run "netsh -c interface dump > C:\TEMP\red_network.txt"
WS.Run "netsh -c interface dump > cmd > C:\TEMP\red_network.txt"
WS.Run "cmd < netsh -c interface dump > C:\TEMP\red_network.txt"
WS.Run "netsh -c interface dump > command.com > C:\TEMP\red_network.txt"
WS.Run "command.com < netsh -c interface dump > c:\red_network.txt"
Set wShell = CreateObject("WScript.Shell")
Set oExec = wShell.Exec("cmd.exe /c netsh.exe -c interface dump > C:\TEMP\red_network.txt")
MsgBox oExec.StdOut.ReadAll()
だと如何でしょう。(試していません)
別のコマンドですが、以下のコードで動いています。
Shell.Run "cmd /C ""dir /s C:\ > C:\" & strFileName & ".txt"""
Set Shell = CreateObject("WScript.Shell")
が抜けてました。すみません。
-----------------------------------------------
Set wShell = CreateObject("WScript.Shell")
Set oExec = wShell.Exec("cmd.exe /c netsh.exe -c interface dump > C:\TEMP\red_network.txt")
MsgBox oExec.StdOut.ReadAll()
-----------------------------------------------
で上手く行きました。
ありがとうございました。
同じように
--------------------------------------------------
Set wShell = CreateObject("WScript.Shell")
Set oExec = wShell.Exec("cmd.exe /c Xcopy /h /k /r /d \\サーバー名\redirect\%USERNAME%\Application Data\Microsoft\Outlook\outlook.pst D:\%USERNAME%\Outlook")
--------------------------------------------------
とやったところ、上手くコピー出来ませんでした。
コピー元のパスにスペースが入っているからだと思います。(Application Dataのところ)
元々、全体を""でくくっているので、その""のなかをさらに""でくくるとエラーが出ます。
Linuxの場合はパスだけ''でくくると上手くいきそうですが、この場合どのようにすればいいのでしょうか?
> その""のなかをさらに""でくくるとエラーが出ます。
「s = "abc""def"」のようにすると、sには『abc"def』のように記されます。
つまり、文字列中でダブルコーテーションを2つ重ねて「""」と書くと、
1つの「"」として出力されます。「S = """"""」なら、『""』です。