rlemon
rlemon

Reputation: 17666

using phps exec command to launch an application on the server

I'm attempting to run an application on the server, invoking it from PHP using the following code.

$application = "D:\\Program Files (x86)\\ScanBoy\\DM ScanBoy.exe";
exec($application);

Right now the application is 'run' however it crashes instantly. If I just run the application (by double clicking the exe) it runs and everything is fine.

When the application crashes the only error I get is

"{application name} has stopped working. Windows is checking for a solution to the problem"

I have had this problem with running application via c# backend to a ASP.NET page. The solution there was to set the Working Directory. However in php / exec I am unaware of how to set this option.

Any help please?

Upvotes: 0

Views: 340

Answers (2)

genesis
genesis

Reputation: 50966

You can chdir() to change current working directory

Upvotes: 1

JJ.
JJ.

Reputation: 5475

You can either:

  1. Use exec("cd myworkdir/ && D:\\Program Files (x86)\\ScanBoy\\DM ScanBoy.exe"); to change the working directory for that exec command (only)

  2. Use the php chdir() function to change the working directory of the php process.

You can find chdir documentation here: http://php.net/manual/en/function.chdir.php

Upvotes: 2

Related Questions