5

I've got an asp.net mvc website up and running great on the pi, and I'm even blinking an led - however, I would like to take a picture from the site using the raspberry pi camera board. I am attempting to use the following code:

Process proc = new System.Diagnostics.Process();
proc.StartInfo.FileName = "/bin/bash";
proc.StartInfo.Arguments = "raspistill -o image.jpg";
proc.StartInfo.UseShellExecute = false; 
proc.StartInfo.RedirectStandardOutput = true;
proc.Start();

However, every time I try to do that I get the error

user/bin/raspistill: /usr/bin/raspistill: cannot execute binary file

Does anyone have any idea why this isn't working, or how I can run a bash command from mono/C#?

Steve French
  • 209
  • 1
  • 3
  • 14

1 Answers1

3

Update

You need to add the -c option to the argument string for /bin/bash:

    proc.StartInfo.Arguments = "-c raspistill -o image.jpg";

I get the same cannot execute binary file when I try to run /bin/bash /usr/bin/raspistill -? from the command line.

    raspberrypi ~ $ /bin/bash /usr/bin/raspistill -?
    /usr/bin/raspistill: /usr/bin/raspistill: cannot execute binary file

Running /bin/bash -c /usr/bin/raspistill -? works from the command line.

Also, according to this SO article try running /usr/bin/raspistill directly from Process.Start() as shown below:

    Process.Start("/usr/bin/raspistill", "-?");
HeatfanJohn
  • 3,115
  • 3
  • 26
  • 38