doumouyi4039 2016-03-09 12:44
浏览 30
已采纳

是否有可能通过点击html页面上的按钮在我的网络服务器上运行c ++程序? [关闭]

I have done a lot of researching in the last hours only finding results for windows servers.

My problem is that I got a c++ program on a embedded computer which needs to be executed when the user wishes to. That's why I set up a webserver to handle that. So I want to create a html page (already done) with a button called "Start Program", which then executes my c++ program.

I already tried Javascript child_process which somehow didn't work and also php system() call, which was unhandy because it didn't react to the button click alone, but to refreshing of the page too.

Is there a smart way to do that? Thanks!

  • 写回答

1条回答 默认 最新

  • drlnwji79147769 2016-03-09 12:51
    关注

    If you don't want to refresh the page, you can program the button to make an ajax call, using jquery. You can add the following the your html index page:

    <script type="text/javascript" src="https://code.jquery.com/jquery-2.2.1.js"></script>
    <script>
        <!--
        $(document).ready(function() {
            $('#buttonid').on('click', function(e) {
                e.preventDefault(); // prevent page from reloading.
                $.get('/callmyprogram.php');
            });
        });
        -->
    </script>
    

    Also on your html, the ID of the button must match the selector on the JS code above. The selector #buttonid implies that the ID of your button is buttonid. So, the html for the button would be something like:

    <input type="submit" id="buttonid" value="Run C++ program"/>
    

    And then you would have callmyprogram.php call your c++ program:

    <?php
    
    exec("/usr/local/bin/myprogram", $output, $ret);
    echo "output: $output" . PHP_EOL;
    echo "ret: $ret" . PHP_EOL;
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 powerbuilder中的datawindow数据整合到新的DataWindow
  • ¥20 有人知道这种图怎么画吗?
  • ¥15 pyqt6如何引用qrc文件加载里面的的资源
  • ¥15 安卓JNI项目使用lua上的问题
  • ¥20 RL+GNN解决人员排班问题时梯度消失
  • ¥60 要数控稳压电源测试数据
  • ¥15 能帮我写下这个编程吗
  • ¥15 ikuai客户端l2tp协议链接报终止15信号和无法将p.p.p6转换为我的l2tp线路
  • ¥15 phython读取excel表格报错 ^7个 SyntaxError: invalid syntax 语句报错
  • ¥20 @microsoft/fetch-event-source 流式响应问题