Aaron
Aaron

Reputation: 4480

exec not opening up .exe file

I am writing a php script to open a c# application and send two variables into the c# application. When I click on the .exe file in Windows Explorer, the program opens up. However when I run my php script nothing happens.

<?php
 $param1 = "Hello";
 $param2 = "Goodbye";
$execCommand = printf("C:\Users\akatz\Documents\Visual Studio 2012\Projects\WindowsFormsApplication1\WindowsFormsApplication1\bin\Debug\WindowsFormsApplication1.exe %s %s", $param1, $param2);
exec($execCommand);
?>

Upvotes: 0

Views: 87

Answers (1)

Diamondo25
Diamondo25

Reputation: 769

I'm pretty sure you are escaping the U, a, D, V, P and more. I suggest using single-quotes to prevent escaping, and escapeshellarg to prevent issues with the arguments:

<?php
$param1 = "Hello";
$param2 = "Goodbye";
$file = 'C:\Users\akatz\Documents\Visual Studio 2012\Projects  \WindowsFormsApplication1\WindowsFormsApplication1\bin\Debug\WindowsFormsApplication1.exe';
$execCommand = escapeshellarg($file).' '.escapeshellarg($param1).' '.escapeshellarg($param2);
exec($execCommand);
?>

Upvotes: 1

Related Questions