I have the following simple problem with UFT.
My Script is:
Dim testShell
Set testShell = CreateObject ("wscript.shell")
testShell.exec "cmd /K CD C:\ & Dir"
msgbox(testShell.Exec.StdOut)
Which gives me the following error:
Wrong number of Arguments : 'testShell.exec' Line (4): "msgbox(testShell.Exec.StdOut)".
I have looked at several VbScripts so far and there it seems to work with no problems. Why does my script fail? I am very sure it is something very stupid and simple, but i cannot see my error. I just want to get the output of my shell into a variable so i can work with it.
You need the object returned by .Exec to get the .StdOut and its content and /K should be /C:
>> Set testShell = CreateObject ("wscript.shell")
>> Set oExec = testShell.exec("%comspec% /C CD C:\ & Dir")
>> WScript.Echo oExec.StdOut.ReadAll()
>>
Volume in drive C has no label.
...
25.05.2011 19:32 <DIR> apache-ant-1.8.2
...
Related
I made a js script to convert text to speech and running a command line with vbs to keep the console window hidden. I am calling via a command so Im trying to use the parameters passed in to it.
I tried using the '+' operator like in most other languages but it didn't work, then I tried the '&' operator but to no success :(.
Set oShell = CreateObject ("Wscript.Shell")
Dim strArgs
strArgs = "cmd /c node audio.js" + WScript.Arguments.Item(0)
oShell.Run strArgs, 0, false
This
C:\Users\eh
type 56861329.vbs
WScript.Echo "cmd /c node audio.js" + WScript.Arguments.Item(0)
C:\Users\eh
cscript 56861329.vbs MissingSpace
cmd /c node audio.jsMissingSpace
should show the real problem. As #Geert said, & is the VBScript operator for concatenation and should be used.
I forgot a space I feel so dumb
I am really new to .vbs and am not sure how to build this out.
I am running a short script that runs a command in cmd.exe and copies/appends the output to a log file.
I would like to only append the o/p to the log file if the value does not match string"". How do I set this up? any help is much appreciated. I apologise if this question is off topic.
Dim oShell
Set oShell = WScript.CreateObject ("WScript.Shell")
oShell.run "cmd.exe /C cd " & str & ">> log.txt"
Set oShell = Nothing
The pseudo code for the if/else logic is shown below
if (o/p string = "A")
action: do not do anything and end script
else
copy string and append to file log.txt
Thank You
Have you tried looking into the command find?
It allows you to do that without using VBScript
dir | find "string_to_find" >> logfile.txt : copy only the text that matches
dir | find /I "string_to_avoid" >>logfile.txt : same as above but case insensitive
dir | find /v "string_to_avoid" >> logfile.txt : copy all strings that do not match
For more help on find type find /? in a command line.
I am writing a VBScript which I want to use to echo the code of another VBScript into an output file.
However, I am unable to write some of the characters to the output file using this method.
If I use the command line method:
cmd.exe /c "#echo "hello"">output.vbs
This works and the string: "hello" is written to the output file.
However, when I do the same using a VBScript, it does not work.
Set objShell = CreateObject("Wscript.Shell")
objShell.Run "%comspec% /c ""#echo ""hello"">output.vbs"
So, is there a way I can echo it into another file retaining the double quotes?
Thanks.
Your quoting is wrong.
Change this:
objShell.Run "%comspec% /c ""#echo ""hello"">output.vbs"
into this:
objShell.Run "%comspec% /c #echo ""hello"">output.vbs"
My script contains the following code.
Set objShell=CreateObject("WScript.Shell")
ObjShell.Run "vb6/make Project1.vbp Project1.exe"
But my script doesn't make my project compile into exe.
I have the visual basic project Project1.vbp in the same folder which contains the script and the path for vb6 is also set in the Environment variable.
However when I tried to compile the project manually into exe it worked fine, by the command given below
vb6/make Project1.vbp Project1.exe
Kindly suggest some way to resolve my script's problem.
Always use full paths in sutch cases, I presume the error is there.
You can catch the error produced in the following way.
Here with a Ruby script I want to run but deliberatly made a mistake in the path.
Set objShell = CreateObject("WScript.Shell")
command = "cmd.exe /S /C ruby ""C:\Users\Gebruiker\ruby\excel\ru.rb"""
Set objWshScriptExec = objShell.Exec(command)
Set objStdOut = objWshScriptExec.StdOut
Set objStdErr = objWshScriptExec.StdErr
While Not objStdOut.AtEndOfStream
WScript.echo objStdOut.ReadLine
Wend
While Not objStdErr.AtEndOfStream
WScript.echo objStdErr.ReadLine
Wend
' ruby: No such file or directory -- C:/Users/Gebruiker/ruby/excel/ru.rb (LoadError)
I made the following changes
Set objWshScriptExec=objShell.Exec("cmd.exe /S /C vb6/make ""Project1.vbp""")
And it worked.
Since I am a beginner in vbscript, I don't know the function of
/S /C
so please let me know.
I have query related to this topic. Here is my script. I'm using below script to edit users on HP ILo board, it works fine, no error at all.
BUT here I can see cmd prompt, how do I run it in silent mode, i.e I do not want to see any cmd prompt, because I use BMC, so let it run in background, I will check the output later.
As you said I can simply change WScript to CSrcipt. But that does not work.
Any help please, please let me know where to modify.
Set wshShell = WScript.CreateObject ("WScript.Shell")
WshShell.Run "cmd.exe /v:on /k (set MYDIR=C:\Program Files\HP\hponcfg) & cd /d ""!MYDIR!"" & HPONCFG.exe /f Add_User1.xml /l log1.txt > output1.txt"
WScript.Sleep 1*60*1000
WshShell.Run "cmd.exe /v:on /k (set MYDIR=C:\Program Files\HP\hponcfg) & cd /d ""!MYDIR!"" & HPONCFG.exe /f Add_User2.xml /l log2.txt > output2.txt"
Set wshShell = Nothing
Wscript.quit
Regards
Use the second parameter of the .Run method
intWindowStyle Optional. Integer value indicating the appearance of
the program's window. Note that not all programs make use of this
information.
As I know nothing about BMC, I'd start with minimized (7, 6) before I'd try hidden (0).