Shell

From Unify Community Wiki
(Difference between revisions)
Jump to: navigation, search
m (Text replace - "<javascript>" to "<syntaxhighlight lang="javascript">")
m (Text replace - "</javascript>" to "</syntaxhighlight>")
 
Line 8: Line 8:
  
 
var output_of_ls = shell("ls", "-l");
 
var output_of_ls = shell("ls", "-l");
</javascript>
+
</syntaxhighlight>
  
 
== JavaScript - Shell.js ==
 
== JavaScript - Shell.js ==
Line 33: Line 33:
 
     return output;
 
     return output;
 
}
 
}
</javascript>
+
</syntaxhighlight>

Latest revision as of 20:52, 10 January 2012

Author: KeliHlodversson

[edit] Description

This is a replacement for the built-in shell command that was removed from Unity 1.6.1. It is based on the original C# source of the Boo internals in the Boo project.

[edit] Usage

To use it place Shell.js into your project and add an "import Shell;" at the top of your code. Then use it the same way as you used the old shell function:

import Shell;
 
var output_of_ls = shell("ls", "-l");

[edit] JavaScript - Shell.js

import System.Diagnostics;
 
static function shellp(filename : String, arguments : String) : Process  {
    var p = new Process();
    p.StartInfo.Arguments = arguments;
    p.StartInfo.CreateNoWindow = true;
    p.StartInfo.UseShellExecute = false;
    p.StartInfo.RedirectStandardOutput = true;
    p.StartInfo.RedirectStandardInput = true;
    p.StartInfo.RedirectStandardError = true;
    p.StartInfo.FileName = filename;
    p.Start();
    return p;
}
 
static function shell( filename : String, arguments : String) : String {
    var p = shellp(filename, arguments);
    var output = p.StandardOutput.ReadToEnd();
    p.WaitForExit();
    return output;
}
Personal tools
Namespaces

Variants
Actions
Navigation
Extras
Toolbox