0

I tried to run a command in windows cmd using xul to search putty.exe location and write output to a text file.

I used the code below. But it opens cmd window for a second and displays "File not found", and then cmd window closes automatically.

    Components.utils.import("resource://gre/modules/FileUtils.jsm");
    env = Components.classes["@mozilla.org/process/environment;1"]

    if(osName=='WINNT')
    {
        var shell = new FileUtils.File(env.get("COMSPEC"));
        var args = ["/c", "cd\ & C: & dir /s /b putty.exe > E:\\process.txt"];
    }

    process = Components.classes["@mozilla.org/process/util;1"]
                            .createInstance(Components.interfaces.nsIProcess);
    process.init(shell);
    process.runAsync(args, args.length);
    }, false, true);

I checked this code on win xp and 7 both..but didn't get result.

Himanshu
  • 825
  • 2
  • 10
  • 24
  • Don't you think that searching the entire hard drive is an overkill? Depending on what's on it this operation might take an hour or more. If it isn't in the PATH - just ask the user. – Wladimir Palant Oct 11 '12 at 20:45
  • check PATH then ask user. simple. –  Nov 27 '14 at 17:09

1 Answers1

1

Wouldn't it be better if you asked the user to point the file? (via nsIFilePicker)

paa
  • 5,048
  • 1
  • 18
  • 22
  • That's the alternative way. If I type "dir /s /b putty.exe > E:\\process.txt" directly in cmd window then it writes command output to text file successfully, but in above case if I do this using XUL, then it is saying "File not Found". I just want to know it's reason..?? – Himanshu Oct 11 '12 at 04:45
  • Because `cd \ ` will not set the root as the current directory. Use `cd /.` instead. – paa Oct 11 '12 at 10:55