与CGI文件奇怪的行为 [英] Strange behaviour with CGI file

查看:173
本文介绍了与CGI文件奇怪的行为的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一个小项目的allmost完成。在这里面,我使用一些.cgi文件中,我做一个单片机和网络服务器之间的通信。问题是这样的:

I've a small project allmost finished. In it, I use some .cgi files in which I make communication between a microcontroler and a webserver. The problem is the following:

如果我用这个code项目的正常工作:

If I use this code the project works fine:

#!/bin/bash

./moveRight

echo "Status: 204 No Content"
echo "Content-type: text/html"
echo ""

但是当我使用tjis code,什么都不会发生:

but when I use tjis code, nothing happens:

#!/bin/bash

mkdir /tmp/stream
raspistill --nopreview -w 640 -h 480 -q 5 -o /tmp/stream/pic.jpg -tl 100 -t 9999999 -th      0:0:0 &
chmod 777 /dev/ttyAMA0
LD_LIBRARY_PATH=/usr/local/lib mjpg_streamer -i "input_file.so -f /tmp/stream -n pic.jpg" -o "output_http.so -p 8080 -w /var/www" &


echo "Status: 204 No Content"
echo "Content-type: text/plain"
echo ""

我要的是执行这些命令的bash时的CGI叫,你认为有什么可以成为我的问题呢?或此问题的任何解决方法吗?

What I want is to execute those bash commands when the .cgi is called, do you think what can be my problem? Or any workaround for this issue?

编辑:./moveRight是编译的C程序,它移动的电机。我有两个不同的CGI。第一个正确的移动马达,但第二个应该执行一些shell命令,但是当它被称为,什么都不会发生。

./moveRight is a compiled c program which moves a motor. I have two different .cgi. The first one moves the motor correctly but the second one is supposed to execute some shell commands but when it's called, nothing happens.

感谢您!!

推荐答案

尝试先打印的HTTP标头后,执行你的命令:

Try to print the HTTP header first and execute your command after:

#!/bin/bash

echo "Status: 204 No Content"
echo "Content-type: text/plain"
echo ""

mkdir /tmp/stream
raspistill --nopreview -w 640 -h 480 -q 5 -o /tmp/stream/pic.jpg -tl 100 -t 9999999 -th      0:0:0 &
chmod 777 /dev/ttyAMA0
LD_LIBRARY_PATH=/usr/local/lib mjpg_streamer -i "input_file.so -f /tmp/stream -n pic.jpg" -o "output_http.so -p 8080 -w /var/www" &

事实上,如果shell命令打印在stdout的东西,你将有一个状态500 因为你的HTTP标头是不正确的。

Indeed, if the shell commands are printing something on stdout, you will have a status 500 because your HTTP header is not correct.

这篇关于与CGI文件奇怪的行为的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆