[Mono-list] using piep with Process

Robert Jordan robertj at gmx.net
Sat Apr 16 16:36:25 EDT 2011


On 15.04.2011 22:33, Leonel Florin Selles wrote:
> Hi, here I'm again:
>
> Well, now I want to execute this Linux shell command "users | wc -w",
> through this I get the numbers of users that are using the system, for
> example, if there are the user "Florin" and "root" logged, that command
> will give me the number 2, and if your see the command "users" return the
> list
>
> florin root
>
> and using pipe (|) I send this list to "wc -w", which count the numbers of
> words.
>
> Now, using Process in C# I got this
>
> System.Diagnostics.ProcessStartInfo commandDetails = new
> System.Diagnostics.ProcessStartInfo ("users | wc -w");

Pipes are a shell feature. This means that you must
pass this command line to bash:

ProcessStartInfo commandDetails =
   new ProcessStartInfo ("bash", "-c 'users | wc -w'");

or

commandDetails.FileName = "bash";
commandDetails.Arguments = "-c 'users | wc -w'";

Robert



More information about the Mono-list mailing list