Re: [PHP] PHP to access shell script to print barcodes

[email protected] (Richard Quadling)
Newsgroups php.general
Message-ID <[email protected]>
On 23 March 2010 05:48, Jochem Maas <[email protected]> wrote:
> Op 3/23/10 3:27 AM, Rob Gould schreef:
>> I am trying to replicate the functionality that I see on this site:
>>
>> http://blog.maniac.nl/webbased-pdf-lto-barcode-generator/
>>
>> Notice after you hit SUBMIT QUERY, you get a PDF file with a page of barcodes.  That's _exactly_ what I'm after.
>> Fortunately, the author gives step-by-step instructions on how to do this on this page:
>>
>> http://blog.maniac.nl/2008/05/28/creating-lto-barcodes/
>>
>>
>> So I've gotten through all the steps, and have created the "barcode_with_samples.ps" file, and have it hosted here:
>>
>> http://www.winecarepro.com/kiosk/fast/shell/
>>
>> Notice how the last few lines contain the shell-script that renders the postscript:
>>
>> #!/bin/bash
>>
>> BASE=”100″;
>> NR=$BASE
>>
>> for hor in 30 220 410
>> do
>> ver=740
>> while [ $ver -ge 40 ];
>> do
>> printf -v FNR “(%06dL3)” $NR
>> echo “$hor $ver moveto $FNR (includetext height=0.55) code39 barcode”
>> let ver=$ver-70
>> let NR=NR+1
>> done
>> done
>>
>>
>> I need to somehow create a PHP script that "executes" this shell script.  And after doing some research, it sounds like
>> I need to use the PHP exec command, so I do that with the following file:
>>
>> http://www.winecarepro.com/kiosk/fast/shell/printbarcodes.php
>>
>> Which has the following script:
>>
>> <?php
>>
>> $command="http://www.winecarepro.com/kiosk/fast/shell/barcode_with_sample.ps";
>> exec($command, $arr);
>>
>> echo $arr;
>>
>> ?>
>>
>>
>> And, as you can see, nothing works.  I guess firstly, I'd like to know:
>>
>> A)  Is this PHP exec call really the way to go with executing this shell script?  Is there a better way?  It seems to me like it's not really executing.
>
> that's what exec() is for. $command need to contain a *local* path to the command in question, currently your
> trying to pass a url to bash ... which obviously doesn't do much.
>
> the shell script in question needs to have the executable bit set in order to run (either that or change to command to
> run bash with your script as an argument)
>
> I'd also suggest putting the shell script outside of your webroot, or at least in a directory that's not accessable
> from the web.
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>

I think this is a translation of the script to PHP.

<?php
$BASE = 100;
$NR   = $BASE;

foreach(array(30, 220, 410) as $hor) {
	$ver = 740;
	while ($ver >= 40) {
		printf("$hor $ver moveto (%06dL3) (includetext height=0.55) code39
barcode\n", $NR);
		$ver -= 70;
		++$NR;
	}
}



It produces output like ...

30 740 moveto (000100L3) (includetext height=0.55) code39 barcode
30 670 moveto (000101L3) (includetext height=0.55) code39 barcode
30 600 moveto (000102L3) (includetext height=0.55) code39 barcode
30 530 moveto (000103L3) (includetext height=0.55) code39 barcode
30 460 moveto (000104L3) (includetext height=0.55) code39 barcode
30 390 moveto (000105L3) (includetext height=0.55) code39 barcode
30 320 moveto (000106L3) (includetext height=0.55) code39 barcode
30 250 moveto (000107L3) (includetext height=0.55) code39 barcode
30 180 moveto (000108L3) (includetext height=0.55) code39 barcode
30 110 moveto (000109L3) (includetext height=0.55) code39 barcode
30 40 moveto (000110L3) (includetext height=0.55) code39 barcode
220 740 moveto (000111L3) (includetext height=0.55) code39 barcode
220 670 moveto (000112L3) (includetext height=0.55) code39 barcode
220 600 moveto (000113L3) (includetext height=0.55) code39 barcode
220 530 moveto (000114L3) (includetext height=0.55) code39 barcode
220 460 moveto (000115L3) (includetext height=0.55) code39 barcode
220 390 moveto (000116L3) (includetext height=0.55) code39 barcode
220 320 moveto (000117L3) (includetext height=0.55) code39 barcode
220 250 moveto (000118L3) (includetext height=0.55) code39 barcode
220 180 moveto (000119L3) (includetext height=0.55) code39 barcode
220 110 moveto (000120L3) (includetext height=0.55) code39 barcode
220 40 moveto (000121L3) (includetext height=0.55) code39 barcode
410 740 moveto (000122L3) (includetext height=0.55) code39 barcode
410 670 moveto (000123L3) (includetext height=0.55) code39 barcode
410 600 moveto (000124L3) (includetext height=0.55) code39 barcode
410 530 moveto (000125L3) (includetext height=0.55) code39 barcode
410 460 moveto (000126L3) (includetext height=0.55) code39 barcode
410 390 moveto (000127L3) (includetext height=0.55) code39 barcode
410 320 moveto (000128L3) (includetext height=0.55) code39 barcode
410 250 moveto (000129L3) (includetext height=0.55) code39 barcode
410 180 moveto (000130L3) (includetext height=0.55) code39 barcode
410 110 moveto (000131L3) (includetext height=0.55) code39 barcode
410 40 moveto (000132L3) (includetext height=0.55) code39 barcode


No idea if that is accurate or not. If you can run the script by hand
once to confirm, then
-- 
-----
Richard Quadling
"Standing on the shoulders of some very clever giants!"
EE : http://www.experts-exchange.com/M_248814.html
EE4Free : http://www.experts-exchange.com/becomeAnExpert.jsp
Zend Certified Engineer : http://zend.com/zce.php?c=ZEND002498&r=213474731
ZOPA : http://uk.zopa.com/member/RQuadling
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.