Jump to content

Passing a couple variables from PHP to C++


RayJ

Recommended Posts

I'm trying to set up a prototype for my company on a new project. This simple system needs to be accessed through the web, and PHP seemed like the best language for my needs.

 

The following PHP code takes two inputs (currently from dropdown menus) and runs them through the code. The plan is to send both variables to teh corresponding C++ program.

 

The C++ program operated correctly when run from the command line (currently running on Windows XP as I'm just testing out the architecture on my personal machine) but when I use the same syntax to run through the passthru() function, it does not display the information properly. If I ahrd-code the variables in the C++ program, the ouput gets displayed as intended, so I'm assuming it's a problem with my PHP code.

 

Without further ado, here's my basic code:

 

<?php

$age = $_POST["age"];
$gender = $_POST["gender"];

print "Your age is ".$age.".";
print "<br />";
print "Your are ".$gender." in gender.";
print "<br />";
print "<br />";

$command = "C:\Program Files\Microsoft Visual Studio\MyProjects\InputTest\Debug\InputTest.exe ".$age." ".$gender."";
passthru(escapeshellarg($command));

?>

The PHP print statements show up with this formatting, but the raw output from the C++ program does not. I've messed with some other configurations of where to place the variables and get similar results (or the code breaks and displays nothing at all)

Link to comment
https://forums.phpfreaks.com/topic/82729-passing-a-couple-variables-from-php-to-c/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.