Ask a Question

WshShell

sanket2799
Occasional Contributor

WshShell

I am trying to run a command ""DIR > D:\\test1234765437189.txt"" through WshShell, but am unable to run the same. This command is used to copy all the output of command prompt.

 

Also alternative to this is to use "<<D:\\test1234765437189.txt" in continuation to any command.  This also does not work.

Can you please suggest a solution regarding the same

9 REPLIES 9
rraghvani
Trusted Contributor

What does your entire script look like, can you paste your code please?

sanket2799
Occasional Contributor

function testing(){

var bimdumperlocation="C:\\Users\\Sanket.Vaidya\\AppData\\Local\\imodelbridges\\ProStructures\\bimdumper.exe";
var input="--input=C:\\Users\\Sanket.Vaidya\\Downloads\\test.bim";
var dumpschema="--dump-schemas --dump-elements";
var signaturefile=">> C:\\testabcd.txt";
var command=bimdumperlocation+" "+input+" "+dumpschema+" "+signaturefile;

WshShell.Run(command);
}

sanket2799
Occasional Contributor

The command in signature variable is not running.

rraghvani
Trusted Contributor

Does it work, if you run the command in the Command Prompt?

sanket2799
Occasional Contributor

yes, it works, the complete command that forms up is  

C:\Users\Sanket.Vaidya\AppData\Local\imodelbridges\ProStructures\bimdumper.exe --input=C:\Users\Sanket.Vaidya\Downloads\test.bim --dump-schemas --dump-elements >> D:\\test1234474437189.txt

if I enter this command in command prompt then the file test1234474437189.txt is created in 😧 location

 

rraghvani
Trusted Contributor

Could you try,

getActiveXObject("WScript.Shell").Run("Enter you command here");

or

var command = "cmd /c " + "Enter your command here"
var oExe = Sys.OleObject("WScript.Shell");
oExe.Run(command)

 

tristaanogre
Esteemed Contributor

You're trying to write output to the root of C.  Many systems, etc., prevent writing to the root of C for security reasons.  What if you change "signaturefile" to be writing to a subfolder instead?


Robert Martin
[Hall of Fame]
Please consider giving a Kudo if I write good stuff
----

Why automate?  I do automated testing because there's only so much a human being can do and remain healthy.  Sleep is a requirement.  So, while people sleep, automation that I create does what I've described above in order to make sure that nothing gets past the final defense of the testing group.
I love good food, good books, good friends, and good fun.

Mysterious Gremlin Master
Vegas Thrill Rider
Extensions available
sanket2799
Occasional Contributor

Its not issue of C location. I used the below script its working now.

 

var bimdumperlocation="C:\\Users\\Sanket.Vaidya\\AppData\\Local\\imodelbridges\\ProStructures\\bimdumper.exe";
var input="--input=C:\\Users\\Sanket.Vaidya\\Downloads\\test.bim";
var dumpschema="--dump-schemas --dump-elements";
var signaturefile=Project.Variables.Var1 + " C:\\testabcd23.txt";
var command=bimdumperlocation+" "+input+" "+dumpschema+" "+signaturefile;

var cmd1=Sys.OleObject("WScript.Shell").Run("C:\\Windows\\system32\\cmd.exe /c" +command);

rraghvani
Trusted Contributor

The parameter /C Carries out the command specified by string and then terminates.

cancel
Showing results for 
Search instead for 
Did you mean: