Execute a system command: Difference between revisions

Add a Limbo version.
No edit summary
(Add a Limbo version.)
Line 617:
run "cmd.exe /";drive1$;" dir & pause"
</lang>
 
=={{header|Limbo}}==
 
There is no equivalent to Unix's exec() in Inferno per se; commands are just modules that have at least an init() function with the correct signature, and are loaded the same way as any other module. (As a result, there's nothing in the language or OS that prevents a program from acting as both a command and a library except convention.)
 
This version passes its argument list through to ls:
 
<lang Limbo>implement Runls;
 
include "sys.m"; sys: Sys;
include "draw.m";
include "sh.m";
 
Runls: module {
init: fn(ctxt: ref Draw->Context, args: list of string);
};
 
init(ctxt: ref Draw->Context, args: list of string)
{
sys = load Sys Sys->PATH;
ls := load Command "/dis/ls.dis";
if(ls == nil)
die("Couldn't load /dis/ls.dis");
ls->init(ctxt, "ls" :: tl args);
}
 
die(s: string)
{
sys->fprint(sys->fildes(2), "runls: %s: %r", s);
raise "fail:errors";
}</lang>
 
It's not strictly necessary to pass the graphics context to ls, but it is generally a good idea to do so when calling another program.
 
=={{header|Locomotive Basic}}==
32

edits