views:

72

answers:

1

I am looking for a way to launch multiple scripts in a separate process from my main script, but in such a way that they can access copies of variables I've declared. Consider the following example:

Serializable.js:

// Represents serializable data.
function Serializable() { /* ... */ }

SecondaryScript.wsf

// Serializable is not defined here!
FakeMoney.prototype = new Serializable();

function FakeMoney(amount) { /* ... */ }

MainScript.wsf:

<job>
    <script language="JScript" src="Serializable.js"></script>
    <script language="JScript">
        var WshShell = new ActiveXObject("WScript.Shell");

        // `Serializable` is defined here...

        var oExec = WshShell.Exec("cscript SecondaryScript.js");

        WScript.Echo(oExec.Status);
    </script>
</job>

Is there a way to define Serializable for the code in SecondaryScript.js while running SecondaryScript.js in a separate process?

+1  A: 

You could make a different wsf with Serializable.js and SecondaryScript included and run that from the first wsf file using exec.

You can also try using events to communicate variables between scripts using the WScript object, or the WshRemote object (locally) to get script statuses.

In fact, this seems to match the best what you're explaining: Running Scripts Remotely on MSDN. Again, you can do this locally to meet your goal.

Gyuri