Forum Discussion

sanket2799's avatar
sanket2799
Occasional Contributor
2 years ago

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

  • rraghvani's avatar
    rraghvani
    Champion Level 3

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

    • sanket2799's avatar
      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's avatar
        sanket2799
        Occasional Contributor

        The command in signature variable is not running.

  • rraghvani's avatar
    rraghvani
    Champion Level 3

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

    • sanket2799's avatar
      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's avatar
    rraghvani
    Champion Level 3

    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's avatar
    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?

    • sanket2799's avatar
      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's avatar
    rraghvani
    Champion Level 3

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