I've lifted this off stackoverflow and up to a point converted it to run
with c#

 

 

private string ReadCPUinfo()
 {
  ProcessBuilder cmd;
  string result="";                             
  try{
           string[] args = {"/system/bin/cat", "/proc/cpuinfo"};
           cmd = new ProcessBuilder(args);
           Java.Lang.Process process = cmd.Start(); 
//System.IO.Stream instr ; 
//Stream instr = new Stream();
//StreamReader instr = new StreamReader();
//MemoryStream instr = new MemoryStream();
//instr= process.InputStream.;
//process.InputStream.CopyTo(instr,1024);
//InputStream instr = process.GetInputStream();
        byte[] re = new byte[process.InputStream.Length];
        long bytestoread = process.InputStream.Length;
        
           while
(process.InputStream.Read(re,Convert.ToInt32(bytestoread),10) != -1)
               {
                   //System.out.println(new String(re));
                   result = result +     re.ToString();
               }
                   process.InputStream.Close();
               
        } catch(Java.IO.IOException)
        {
        //      ex.printStackTrace();
        }
  return result;
 }

 

 

                

 

This throws an 'operation no supported' exception (interestingly referencing
M. J Pobst!) at the line where I try to get the length of the process
inputstream 

Now OK that might be illegal but I only put that in because the original
code didn't work 

The original code -see below - (as usual ) is java and needs tweaking to run
in c# - I'm not that expert but I succeed on the simpler ones - this has me
stumped 

private String ReadCPUinfo()
{
  ProcessBuilder cmd;
  String result="";
  
  try{
   String[] args = {"/system/bin/cat", "/proc/cpuinfo"};
   cmd = new ProcessBuilder(args);
   
   Process process = cmd.start();
   InputStream in = process.getInputStream();
   byte[] re = new byte[1024];
   while(in.read(re) != -1){
    System.out.println(new String(re));
    result = result + new String(re);
   }
   in.close();
  } catch(IOException ex){
   ex.printStackTrace();
  }
  return result;

 

First there is no 'process.getInputStream' this gives an error in
Monodevelop 

Also the line result=result + new String(re) doesn't work in c# so I've put
in 're.ToString()'  - haven't  found out if it works because I cant get past
the 'operation not supported error' 

Hence my various lines commented out in my example where I tried various
things 

Incidentally the Monodroid API also refers to Java.Lang.Process and shows a
'getInputStream' 

I mean where on earth do you go to find the answer  -

Any help would be worshipped 

Yours in abject exasperation 

Tia

John Murray 

 

                

_______________________________________________
Monodroid mailing list
Monodroid@lists.ximian.com

UNSUBSCRIBE INFORMATION:
http://lists.ximian.com/mailman/listinfo/monodroid

Reply via email to