I've been trying for a few weeks now to fire a batch file that runs the command to scan a document from a scanner attached to the same machine.
I'm working on a web app that (using PHP) is meant to gather information from a patron who is trying to apply for a membership at my establishment. I'm at a loss for how to explain what I've tried because I think I've tried just about every combination of exec(), shell_exec() and system() I can think of.
I have PHP permissions set to execute, and (I think) all of the permissions on any other files set correctly but I'm still getting nowhere.
Any pointers and/or assistance is greatly appreciated as this is the only piece of this app that is keeping me from finishing.
References: I'm using an open source piece of software to do the actual scanning called wia-cmd-scanner. But to note, I have also tried NAPS2 with the same lack of results The very small site is hosted in IIS. Scan.bat is a simple one liner.
c:\inetpub\websvcs\selfserve\kiosk\bin\wia-cmd-scanner.exe /w 94.75 /h 53.975 /dpi 600 /color RGB /format JPG /output .\id.jpg
Various funcions in PHP I have tried are:
Executing via batch:
<?php
$batchFile = "C:\\inetpub\\websvcs\\selfserve\\kiosk\\bin\\scan.bat"
exec("cmd /c \"{$batchFile}\"");
?>
Executing directly:
$command = "bin\\wia-cmd-scanner.exe";
$args = " /w 94.75 /h 53.975 /dpi 600 /color RGB /format JPG /output .\id.jpg";
$fire = $command . $args;
exec("cmd /c {$fire} 2>&1");
Same with shell_exec():
$command = "bin\\wia-cmd-scanner.exe";
$args = " /w 94.75 /h 53.975 /dpi 600 /color RGB /format JPG /output .\id.jpg";
$fire = $command . $args;
shell_exec($fire);
These are just 3 examples but I feel like I've tried 30 at least. In many cases I got no error and nothing logged but nothing scanned either. In some cases It would give me Return Value:1, but nothing more. And the last function I tried.
<?php
$batchFile = "C:\\inetpub\\websvcs\\selfserve\\kiosk\\bin\\scan.bat";
echo system("cmd /c \"{$batchFile}\"");
?>
Gave the error
"Exception occured: Cannot create ActiveX component."
I feel like I may have been getting close but I just can't figure out what is keeping this thing from firing. My guess is it is something to do with escaping, but I'm not sure where. Admittedly I am fairly new to programming in PHP.
Any help is appreciated.
Edit: Using this code saved as new39.php...
<?php
$command = "c:\\inetpub\\websvcs\\selfserve\\kiosk\\bin\\wia-cmd-scanner.exe";
$args = " /w 94.75 /h 53.975 /dpi 600 /color RGB /format JPG /output c:\\inetpub\\websvcs\\selfserve\\kiosk\\temp\\id.jpg";
$fire = $command . $args;
$output = [];
$return_var = 0;
exec($fire);
echo "Return status: " . $return_var . "\n";
?>
I can run execute from the command line (eg: c:\PHP c:\inetpub\websvcs\selfserve\kiosk\new.39.php) and the code runs as it should. However when I open a browser and load the same file I get Return Status: 0. The scanner does not activate or of course save anything.
bin\\wia-cmd-scanner.exeto FULL PATH (e.g. c:\xxxx\xxxx\xxxx\bin\wia-cmd-scanner.exe) and try again. (do not use batch file)<?php $command = "c:\\inetpub\\websvcs\\selfserve\\kiosk\\bin\\wia-cmd-scanner.exe /w 94.75 /h 53.975 /dpi 600 /color RGB /format JPG /output .\id.jpg"; $output = []; $return_var = 0; exec($command, $output, $return_var); echo "Output:\n"; foreach ($output as $line) { echo $line . "\n"; } echo "Return status: " . $return_var . "\n"; ?>I get the error... Output: Exception occured: Cannot create ActiveX component. Return status: 0"c:\\inetpub\\websvcs\\selfserve\\kiosk\\bin\\wia-cmd-scanner.exe /w 94.75 /h 53.975 /dpi 600 /color RGB /format JPG /output .\id.jpg"and yes, that does activate the scanner and save the file. I can also run that via PHP from the command line eg:"c:\PHP c:\inetpub\websvcs\selfserve\kiosk\new39.php"and that TOO activates the scanner and saves the file. However, when I open a browser and surf to "localhost/new39.php" I get only "Return Status: 0". Scanner does not activate.