Forum Discussion

mmorioka's avatar
New Contributor
12 years ago

How to execute command line statement (dir) and return the value

I have a dir statement that I would like to run via Jscript.  I would like to call the cmd.exe process and then execute this statement: dir /a /s c:\ |find /c /v "".

Here is my sample code, but I can't figure out how to get it to work:

  var WScriptObj = Sys.OleObject("WScript.Shell");

  // Ping the server

  var ExecOperation = WScriptObj.Exec("cmd /c dir /a /s c:\ |find /c /v \"\"");

  // Check the operation's status

  while (ExecOperation.Status == 0)


  // Obtain the operation's exit code

  var ExCode = ExecOperation.ExitCode;

  // Obtain the application's StdOut stream

  var StdOut = ExecOperation.StdOut;

  if (ExCode == 0)

    Log.Message("Connection succeeded", StdOut.ReadAll())


    Log.Error("Server is unavailable", StdOut.ReadAll())

3 Replies

  • mmorioka's avatar
    New Contributor
    Yes, the STD out is empty and no values are returned.  I cannot tell if the cmd operation executed properly