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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.