[Mono-list] Scripting the Linux OS with Mono

ted leslie tleslie at tcn.net
Fri Nov 11 14:41:48 EST 2005


On Fri, 11 Nov 2005 19:34:51 +0000
Elliott Draper <el at eldiablo.co.uk> wrote:

> Hi Abe,
> 
> Abe Gillespie wrote:
> 
> >*snip
> >mono script_host.exe MyScript.cs myarg1 myarg2
> >
> >*snip
> >Has anyone out there done something or started a project like this?
> >  
> >
> Give the attached source code a try :-) I'm not claiming it's perfect, 
> but it's something I knocked up while I was bored this afternoon, and 
> you may be able to use it or tweak it to what you need. It uses the 
> features of CodeDom, available both in .Net and Mono, to compile the 
> source file to an in-memory assembly, where the code can then be 
> executed. The file "MonoScript.cs" can be compiled on its own to provide 
> the actual script execution tool, and also attached is a sample "script" 
> file ("Test.cs") that you can use to give it a bash. Simply compile the 
> MonoScript tool:
> 
> mcs MonoScript.cs
> 
> And then it's as easy as running:
> 
> mono MonoScript.exe --sourceFile:Test.cs
> 
> If for example your source file has a reference to System.Data then you 
> can simply run:

you could parse for the popular ones and illiminate this step right?

> 
> mono MonoScript.exe --sourceFile:Test.cs --references:System.Data.dll
> 
> For the full usage of the program, run:
> 
> mono MonoScript.exe --displayUsage:true
> 
> Any arguments you specify that MonoScript doesn't recognize will be 
> forwarded onto the "script" application, you can see this by appending 
> as many arguments as you want to the test script:
> 
> mono MonoScript.exe --sourceFile:Test.cs test1 test2 test3
> 
> Have a play, and give me a shout if you run into any bugs or problems 
> with it and I'll do my best to fix them, failing that, jump right in and 
> tweak the code yourself ;-)
> 
> If anyone else finds the code useful, let me know and I'll get the 
> entire thing (project files, a build file maybe, a bigger testsuite 
> perhaps?) up on my website as a package. Likewise if anyone has any 
> comments, let me have 'em!
> 
> >-Abe
> >  
> >
> Cheers,
> -= El =-
> 
> >On 11/10/05, Kornél Pál <kornelpal at hotmail.com> wrote:
> >  
> >
> >>Hi,
> >>
> >>You have to compile C# code using mcs that will result in a .exe assembly
> >>that can be executed using mono:
> >>
> >>$mcs some.cs
> >>$mono some.exe
> >>
> >>If you prefer you can write a shell script that will do this as a single
> >>step.
> >>
> >>Kornél
> >>
> >>----- Original Message -----
> >>From: "Abe Gillespie" <abe.gillespie at gmail.com>
> >>To: "MonoList" <mono-list at lists.ximian.com>
> >>Sent: Friday, November 11, 2005 1:02 AM
> >>Subject: [Mono-list] Scripting the Linux OS with Mono
> >>
> >>
> >>Hey all,
> >>
> >>I was wondering if there's any easy way to run C# scripts in Mono.
> >>I'm fairly new to Linux (just at about a year) and I'd like to avoid
> >>learning yet another language (Perl, sh, etc.).  Has anyone written a
> >>.Net program that takes a file as input and runs that code?  Perhaps
> >>Mono can do this natively?  How cool would it be to have startup
> >>scripts written in C#?!
> >>
> >>Thanks for the help as always.
> >>-Abe
> >>_______________________________________________
> >>Mono-list maillist  -  Mono-list at lists.ximian.com
> >>http://lists.ximian.com/mailman/listinfo/mono-list
> >>
> >>
> >>    
> >>
> >_______________________________________________
> >Mono-list maillist  -  Mono-list at lists.ximian.com
> >http://lists.ximian.com/mailman/listinfo/mono-list
> >  
> >
> 
> 


More information about the Mono-list mailing list