954,587 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

Need help php exec()

Hello,

I am trying to connect a unix server using ssh (phpseclib) and running an external program like 'C' program. I am using exec() to run .exe. My code looks this way

echo $ssh->exec('./demo.exe');


demo.exe is a executable for program to add two numbers and the inputs are hardcoded within the 'C' program.

This piece of code works perfectly when the inputs are hardcoded in the 'C' program. But when I try to pass the arguments to exec(), the php script becomes unresponsive. After modification to accept inuts for .exe, my code looks this way,

echo $ssh->exec("./demo.exe, '10 20'");


where demo.exe is a, executable for a simple program to add two numbers and 10 and 20 are inputs to the executable. I did modify the code as some of my friends suggested like

$ssh->exec("./demo.exe '10' '20'"); 
$ssh->exec("./demo.exe ; '10 20'"); 
$ssh->exec('./demo.exe 10 20');


but none of them worked. All the above php scripts became unresponsive. Could any one throw some light on this. Any inputs on this are greately appreciated.

Thanks in advance..

ksyz_1
Newbie Poster
2 posts since Aug 2010
Reputation Points: 10
Solved Threads: 0
 

Are you on a Windows system? (Guessing by the EXE extension but I may be wrong)
If so, you need to give Apache2 permision to 'Interact with the desktop'
To do this go Start->Run->(Type 'services.msc')->(Locate the Apache2 service)->Right Click->Properties->Log On
Make sure 'Local System Account' is selected then check 'Allow service to interact with desktop'
If you're on a UNIX based system ignore all that =)

samarudge
Posting Whiz
359 posts since May 2008
Reputation Points: 26
Solved Threads: 31
 

Hey Thanks for your reply, I am working in unix server.. so I dont think this will work.
I used .exe to represent "a.out" in C program. Probably something to do with exec() so that it accepts inputs..

ksyz_1
Newbie Poster
2 posts since Aug 2010
Reputation Points: 10
Solved Threads: 0
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You
View similar articles that have also been tagged: