Jump to content

Using Windows command line through PHP


olamur

Recommended Posts

I have a question about using the command line through PHP.

 

In my code, BarcodeGenerationTool.exe prints to file using windows printing calls.

 

I tried this

 

pclose(popen("BCStudio.exe $output_file", "w")); // 
pclose(popen("BarcodeGenerationTool.exe $output_file", "w"));

 

and this

 

$cmd = "@ECHO OFF

BCStudio.exe $output_file

BarcodeGenerationTool.exe $output_file

exit";

$fh = fopen($bat_outfile,"w") or die($php_errormsg);
fwrite($fh,$cmd) or die($php_errormsg);
fclose($fh);
exec($bat_outfile . " > NUL:") or die($php_errormsg); // appears stuck in shell
// exec($bat_outfile") // this also doesn't work

 

but when I tried running commands through PHP, as opposed to executing them manually from a Windows shell, the output of BarcodeGenerationTool.exe (a PCL file) contains a different 0x00 padding scheme, compared to when I execute the command manually through the Windows shell. In other words, two different files get outputted depending on where the commands are run (automatically through PHP vs. manual Windows shell), even though both do print out.

 

Any directions on how to detect differences between the two process would help me a lot.

 

 

By the way, does anyone know of any PHP print to file functions, or of any way to call such functions through PHP (even if not directly)?

 

Link to comment
Share on other sites

well file_get_contents will work for the file content issue.

 

The only issue I can see is that your server has a different version of cmd making your syntax slightly off and outputting the extra lines.  What you should do is build a second .exe to execute your bargraph perfectly (i.e turn echo off output file creation etc.) and then just exec(BAR_START_FILE.exe)

Link to comment
Share on other sites

The file contents were ok (it does print, but the padding problem prevents post-processing).

 

I made an .exe (in C) to call barcode.bat through system(), but the same kind of problem still arose. Namely, calling the .exe in the Windows shell worked, but calling it through PHP did not.

 

 

 

What do you mean by a different version of cmd? I use the same syntax when manually entering commands through the shell. Could you tell me how I could reconfigure the server's (Apache 2.2.6 with defaults I think) cmd stuff?

 

 

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.