Question

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.

Was it helpful?

Solution

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

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top