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 制裁名单20240508芯片厂商
  • ¥20 易康econgnition精度验证
  • ¥15 msix packaging tool打包问题
  • ¥28 微信小程序开发页面布局没问题,真机调试的时候页面布局就乱了
  • ¥15 python的qt5界面
  • ¥15 无线电能传输系统MATLAB仿真问题
  • ¥50 如何用脚本实现输入法的热键设置
  • ¥20 我想使用一些网络协议或者部分协议也行,主要想实现类似于traceroute的一定步长内的路由拓扑功能
  • ¥30 深度学习,前后端连接
  • ¥15 孟德尔随机化结果不一致