CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Beginner:
i have an emergency please help

 



gerble1000
User

Aug 15, 2012, 6:36 AM

Post #1 of 35 (5191 views)
i have an emergency please help Can't Post

i had a virus recently and needed to reformat.
i have installed php and perl again but the php files no longer work in the cgi-bin directory. i only have 1 file i need to work,
this was the working command

Code
system('roundimage.php');


i could do with this perl script calling the file in the htdocs folder.
like so
system('C:/"Program Files (x86)"/"Apache Software Foundation"/Apache2.2/htdocs/customers/$domainname/roundimage.php');

but this does not work, i am sure its just the sintax is incorrect as i can get the php file running from the browser


Laurent_R
Veteran / Moderator

Aug 15, 2012, 7:06 AM

Post #2 of 35 (5184 views)
Re: [gerble1000] i have an emergency please help [In reply to] Can't Post

Hmmm, I am almost never using Perl under Windows, so my advice may be clumsy or clunky, but if you write:


Code
system('C:/"Program Files (x86)"/"Apache Software Foundation"/Apache2.2/htdocs/customers/$domainname/roundimage.php');


the $domainname variable will not be interpreted correctly, because the command is created between single quotes (no interpolation of variables).

You have to construct your command differently. Perhaps changing double quotes to single quotes and single quotes to double quotes will be sufficient to solve the problem.

If this does not work, you can first construct the command into a variable and then run it.

Something like that:


Code
my $command = 'C:/"Program Files (x86)"/"Apache Software Foundation"/Apache2.2/htdocs/customers/'; 
$command = $command . $domainname . '/roundimage.php';
system ("$command");



gerble1000
User

Aug 15, 2012, 7:21 AM

Post #3 of 35 (5182 views)
Re: [Laurent_R] i have an emergency please help [In reply to] Can't Post

no joy
have you any other ideas.
it does not even like it when i leave out the variable like this

Code
system('C:/Program Files (x86)/Apache Software Foundation/Apache2.2/htdocs/customers/mydomainname/roundimage.php');



(This post was edited by gerble1000 on Aug 15, 2012, 7:32 AM)


Laurent_R
Veteran / Moderator

Aug 15, 2012, 7:37 AM

Post #4 of 35 (5173 views)
Re: [gerble1000] i have an emergency please help [In reply to] Can't Post

Well, maybe you can change directory first (chdir command), and then issue the command.


Code
system('roundimage.php');


If you print the current directory first, you will be probably be able to narrow down what the issue is, i.e. to find out if the problem is in the directory name or in the command line.


FishMonger
Veteran / Moderator

Aug 15, 2012, 7:42 AM

Post #5 of 35 (5172 views)
Re: [gerble1000] i have an emergency please help [In reply to] Can't Post


Code
my $command = 'C:/Program Files (x86)/Apache Software Foundation/Apache2.2/htdocs/customers/mydomainname/roundimage.php'; 

system($command) == 0 or die "system call failed $?";



gerble1000
User

Aug 15, 2012, 7:51 AM

Post #6 of 35 (5170 views)
Re: [FishMonger] i have an emergency please help [In reply to] Can't Post

still no joy,
no errors but does not run the php script :(


gerble1000
User

Aug 15, 2012, 7:56 AM

Post #7 of 35 (5169 views)
Re: [Laurent_R] i have an emergency please help [In reply to] Can't Post

not sure what you mean by print the current directory,
im guessing you mean display whats going on to the screen ,
not sure exactly


FishMonger
Veteran / Moderator

Aug 15, 2012, 8:00 AM

Post #8 of 35 (5166 views)
Re: [gerble1000] i have an emergency please help [In reply to] Can't Post


In Reply To
still no joy,
no errors but does not run the php script :(


I don't believe that.

If the php script did not get executed, then the die statement would have been executed which would have generated the error message and $? would have held -1 as its value.


gerble1000
User

Aug 15, 2012, 8:04 AM

Post #9 of 35 (5164 views)
Re: [FishMonger] i have an emergency please help [In reply to] Can't Post

at the very end of my script i have
print"settings successfully changed";

and thats all i get,
but when i ran your modification it just hangs as if its uploading images thats 100gb large :(

just rechecked and it doesnt hang it actually gets to the end of the script but the perl script was not run


(This post was edited by gerble1000 on Aug 15, 2012, 8:06 AM)


gerble1000
User

Aug 15, 2012, 8:11 AM

Post #10 of 35 (5161 views)
Re: [FishMonger] i have an emergency please help [In reply to] Can't Post

this is whats going on in the script before the system command


Code
 
my $upload_filehandle = $query->upload("uploadfile1");
open ( UPLOADFILE, ">$result1/file.jpg" ) or die "failed to open '$upload_dir/1.jpg' $!"; binmode UPLOADFILE; while ( <$upload_filehandle> ) { print UPLOADFILE; } close UPLOADFILE;
copy("$result1/file.jpg","$result1/thumb1.jpg");

system("PhotoResize700x500ICO.exe $result1/file.jpg");
system("PhotoResize140x100ICO.exe $result1/thumb1.jpg");

move("$result1/file.jpg","C:/Program Files (x86)/Apache Software Foundation/Apache2.2/htdocs/customers/$domainname/file.jpg");



my $command = 'C:/Program Files (x86)/Apache Software Foundation/Apache2.2/htdocs/customers/hiddendomainname/roundimage.php';

system($command) == 0 or die "system call failed $?";

and i gets the file.jpg to the correct location so that means that the path is correct in the move command


FishMonger
Veteran / Moderator

Aug 15, 2012, 8:13 AM

Post #11 of 35 (5160 views)
Re: [gerble1000] i have an emergency please help [In reply to] Can't Post

You're not making any sense. You need to provide more details and your code. However, if your code anything like what you posted in your earlier question, then don't bother, because I'm not going to waste my time troubleshooting that junk.


gerble1000
User

Aug 15, 2012, 11:43 AM

Post #12 of 35 (5149 views)
Re: [FishMonger] i have an emergency please help [In reply to] Can't Post

it does not even work with the basic script here



Code
#!/strawberry/perl/bin/perl -w 



use CGI::Carp qw( fatalsToBrowser );

print "Content-Type: text/html\n\n";








my $command = 'C:/Program Files (x86)/Apache Software Foundation/Apache2.2/htdocs/customers/mydomainname/roundimage.php';

system($command) == 0 or die "system call failed $?";

print "<h1><center>SUCCESSFULLY CHANGED</center></h1>";



(This post was edited by gerble1000 on Aug 15, 2012, 11:44 AM)


FishMonger
Veteran / Moderator

Aug 15, 2012, 11:56 AM

Post #13 of 35 (5145 views)
Re: [gerble1000] i have an emergency please help [In reply to] Can't Post

You need to be more specific.

What does "does not even work" mean?

What part doesn't work?

What results are you seeing in the browser?

I suspect that the php file is being executed, but does not do what you expect.

What are you expecting it to do and what is actually happening?


gerble1000
User

Aug 15, 2012, 12:19 PM

Post #14 of 35 (5142 views)
Re: [FishMonger] i have an emergency please help [In reply to] Can't Post

when i got to the url of the .pl script and run it,
it just hangs like im connecting to a lagging server. just loading loading ect.
but if i play with the code a bit i can get it to display "successfully changed" but check to see if the php script has done its job and it has not.
and i can go to the php script url and it will run fine.
i am researching the issue and some people say it may be the program files (86) being to long so i tried getting the short versions like progra~2 and that did not do anything either.

i wish i could just get an error message or something

i have recently installed windows, could it be some security settings or something i am not setting


(This post was edited by gerble1000 on Aug 15, 2012, 12:20 PM)


FishMonger
Veteran / Moderator

Aug 15, 2012, 12:24 PM

Post #15 of 35 (5140 views)
Re: [gerble1000] i have an emergency please help [In reply to] Can't Post

What happens when you execute the php script from the command line using the full path like you have in the perl script?


gerble1000
User

Aug 15, 2012, 12:30 PM

Post #16 of 35 (5138 views)
Re: [FishMonger] i have an emergency please help [In reply to] Can't Post

when i go to the folder in cmd and open the script it just opens in notepad. im guessing i am not do this right.
whats the sintax to run from dos
i forgot to put php in front :)
it runs perfectly fine from cmd

these dont work either but the script does finish


Code
system("C:/Progra~2/Apache~1/Apache2.2/htdocs/custom~1/firstt~1/roundimage.php c:/php/php.exe"); 


system("C:\Program Files (x86)\Apache Software Foundation\Apache2.2\htdocs\customers\hiddendomainname\roundimage.php c:\php\php.exe");



(This post was edited by gerble1000 on Aug 15, 2012, 12:47 PM)


FishMonger
Veteran / Moderator

Aug 15, 2012, 12:39 PM

Post #17 of 35 (5135 views)
Re: [gerble1000] i have an emergency please help [In reply to] Can't Post

There's your problem

You need to setup a .php filetype association so that Windows knows to execute the script.

The other option is to adjust your system call so that it executes php and passes the script as an arg, which is what you did on the command line.


FishMonger
Veteran / Moderator

Aug 15, 2012, 12:46 PM

Post #18 of 35 (5131 views)
Re: [gerble1000] i have an emergency please help [In reply to] Can't Post


Code
my @command = '/path/to/php', 'C:/Program Files (x86)/Apache Software Foundation/Apache2.2/htdocs/customers/mydomainname/roundimage.php';  

system(@command) == 0 or die "system call failed $?";



(This post was edited by FishMonger on Aug 15, 2012, 12:46 PM)


gerble1000
User

Aug 15, 2012, 12:46 PM

Post #19 of 35 (5129 views)
Re: [FishMonger] i have an emergency please help [In reply to] Can't Post

ok i have done the file type association i think.
is this what you mean by the system call


Code
system("C:/Program Files (x86)/Apache Software Foundation/Apache2.2/htdocs/customers/hiddendomainname/roundimage.php c:/php/php.exe");


as this did not work either but did finish the script

there is something strange i noticed,
it worked fine when i navigated to the directory in cmd and the typed "php roundimage.php"
but if i type " php C:/Progra~2/Apache~1/Apache2.2/htdocs/custom~1/firstt~1/roundimage.php"

then it does nothing with no error,
which is what the system call is doing,
any idea's


(This post was edited by gerble1000 on Aug 15, 2012, 12:58 PM)


gerble1000
User

Aug 15, 2012, 1:35 PM

Post #20 of 35 (5113 views)
Re: [FishMonger] i have an emergency please help [In reply to] Can't Post

ok your right with the associate .php
i have noticed about 50 notepads open in task manager.
how do i associate with php as i right clicked and opened with c:\php\php.exe and it is still opening in notepad.
is there something i have to do to make it an executable php


FishMonger
Veteran / Moderator

Aug 15, 2012, 1:48 PM

Post #21 of 35 (5112 views)
Re: [gerble1000] i have an emergency please help [In reply to] Can't Post

http://support.microsoft.com/kb/307859

http://www.winvistaclub.com/t19.html


gerble1000
User

Aug 15, 2012, 1:56 PM

Post #22 of 35 (5110 views)
Re: [FishMonger] i have an emergency please help [In reply to] Can't Post

i have done all of those things and the file has the php logo on it but when i open the file it brings up a cmd screen for a split second and thats it, but i can still run it from cmd with the php command


FishMonger
Veteran / Moderator

Aug 15, 2012, 2:03 PM

Post #23 of 35 (5109 views)
Re: [gerble1000] i have an emergency please help [In reply to] Can't Post

Can you execute it from the command line without putting php before the path to the script?

If so, how long does it take to execute and return you to the prompt?


gerble1000
User

Aug 15, 2012, 2:21 PM

Post #24 of 35 (5107 views)
Re: [FishMonger] i have an emergency please help [In reply to] Can't Post

just checked , no i cant.
i have a feeling that my php is corrupt as when i run the script like i did before it works but also shows a lot of corruped code that scrolls for nearly 1 minute


FishMonger
Veteran / Moderator

Aug 15, 2012, 2:25 PM

Post #25 of 35 (5106 views)
Re: [gerble1000] i have an emergency please help [In reply to] Can't Post

Your php installation may or may not be corrupt, but your .php file type association is not setup correctly.


gerble1000
User

Aug 15, 2012, 2:42 PM

Post #26 of 35 (1798 views)
Re: [FishMonger] i have an emergency please help [In reply to] Can't Post

am i right in saying that it needs to be associated with c:/php/php.exe or is there some other exe ot should be associated with


FishMonger
Veteran / Moderator

Aug 15, 2012, 2:48 PM

Post #27 of 35 (1797 views)
Re: [gerble1000] i have an emergency please help [In reply to] Can't Post

That is what the .php extension should be associated with so that you can execute the scripts without prepending php.

If you can't execute the script directly, then that file type association is not setup correctly.


(This post was edited by FishMonger on Aug 15, 2012, 2:49 PM)


gerble1000
User

Aug 16, 2012, 6:53 AM

Post #28 of 35 (1785 views)
Re: [FishMonger] i have an emergency please help [In reply to] Can't Post

ok i am now getting the error message from your script,
i have reinstalled php finally ,

Code
my $command = 'C:/Program Files (x86)/Apache Software Foundation/Apache2.2/htdocs/customers/myhiddendomainname/roundimage.php';  

system($command) == 0 or die "system call failed $?";


this is the error message

system call failed 256 at C:/Program Files (x86)/Apache Software Foundation/Apache2.2/cgi-bin/mydomainname//update2.pl line 20.

line 20 is the system command


gerble1000
User

Aug 16, 2012, 6:58 AM

Post #29 of 35 (1783 views)
Re: [FishMonger] i have an emergency please help [In reply to] Can't Post

if i use this command
system('c:/php/php roundimage.php');
it works fine but outputs lots of junk code to the screen after it finishes like so.


Code
PNG  IHDRY IDATxwxՙ?}Fj\r7%Y$$rwMnؔˆ$6҃M %{cma["ɶz4M?d$}=cKr{{rF=BQ.9 `3#<fwNw.O9?W4~ tࡍ0?gFV>}iPi#ɇIF|sdgn8N !t'ôXBܮi]my'y{.<o iZl7 !lB4MGyM&q3=Ox y›GgD!Mc4wD+xG7<㬐'y{.<4.:#fjUy|дj#<›9g+΁NS3:H?l7b}:?`XiB~$GyGyG2lClvpIxP#<#<#GzExnyGyG?~jnW&9ȯ3ޏs{shmD36{:7ÛGst:B?!<#<#<>x4=GyGyU-p:A1ėJCȧ4m#?ȧ4+) |JCtSt:]@<#<#<n) 6'<#<#< BT#<#<UlJ[GyB7Ŀ9gbjӡƳP[4@{pn8W۟KrQ+bmPVKpI~6߃1Ը<>Jj͚}pk4c hg4k_f3ޟdd


just lots of this stuff.
but that does work but does not finish the perl script and show the print"successfully finished";


FishMonger
Veteran / Moderator

Aug 16, 2012, 7:09 AM

Post #30 of 35 (1780 views)
Re: [gerble1000] i have an emergency please help [In reply to] Can't Post

Looks like you need to troubleshoot the roundimage.php script.

If you want to have better control over the execution and output of the php script, then instead of using a system call, you should use IPC::Open3.
http://search.cpan.org/~rjbs/perl-5.16.1/ext/IPC-Open3/lib/IPC/Open3.pm

BTW, the 256 exit code needs to be bit shifted to get the actual code, which in this case is an exit code of 1. Does the php script have an explicit exit statement?


gerble1000
User

Aug 16, 2012, 7:21 AM

Post #31 of 35 (1779 views)
Re: [FishMonger] i have an emergency please help [In reply to] Can't Post

this is the php script


Code
<?php 

$sourceImageFile = "file.jpg";
$radius = "20";
# test source image
if (file_exists($sourceImageFile)) {
$res = is_array($info = getimagesize($sourceImageFile));
}
else $res = false;

# open image
if ($res) {
$w = $info[0];
$h = $info[1];
switch ($info['mime']) {
case 'image/jpeg': $src = imagecreatefromjpeg($sourceImageFile);
break;
case 'image/gif': $src = imagecreatefromgif($sourceImageFile);
break;
case 'image/png': $src = imagecreatefrompng($sourceImageFile);
break;
default:
$res = false;
}
}

# create corners
if ($res) {

$q = 5; # change this if you want
$radius *= $q;

# find unique color
do {
$r = rand(0, 255);
$g = rand(0, 255);
$b = rand(0, 255);
}
while (imagecolorexact($src, $r, $g, $b) < 0);

$nw = $w*$q;
$nh = $h*$q;

$img = imagecreatetruecolor($nw, $nh);
$alphacolor = imagecolorallocatealpha($img, $r, $g, $b, 127);
imagealphablending($img, false);
imagesavealpha($img, true);
imagefilledrectangle($img, 0, 0, $nw, $nh, $alphacolor);

imagefill($img, 0, 0, $alphacolor);
imagecopyresampled($img, $src, 0, 0, 0, 0, $nw, $nh, $w, $h);

imagearc($img, $radius-1, $radius-1, $radius*2, $radius*2, 180, 270, $alphacolor);
imagefilltoborder($img, 0, 0, $alphacolor, $alphacolor);
imagearc($img, $nw-$radius, $radius-1, $radius*2, $radius*2, 270, 0, $alphacolor);
imagefilltoborder($img, $nw-1, 0, $alphacolor, $alphacolor);
imagearc($img, $radius-1, $nh-$radius, $radius*2, $radius*2, 90, 180, $alphacolor);
imagefilltoborder($img, 0, $nh-1, $alphacolor, $alphacolor);
imagearc($img, $nw-$radius, $nh-$radius, $radius*2, $radius*2, 0, 90, $alphacolor);
imagefilltoborder($img, $nw-1, $nh-1, $alphacolor, $alphacolor);
imagealphablending($img, true);
imagecolortransparent($img, $alphacolor);

# resize image down
$dest = imagecreatetruecolor($w, $h);
imagealphablending($dest, false);
imagesavealpha($dest, true);
imagefilledrectangle($dest, 0, 0, $w, $h, $alphacolor);
imagecopyresampled($dest, $img, 0, 0, 0, 0, $w, $h, $nw, $nh);

# output image
$res = $dest;
imagedestroy($src);
imagedestroy($img);
}




header('Content-type: image/png');
imagepng($res, "file.png");
Imagepng($res);
imagedestroy($res);
?>



FishMonger
Veteran / Moderator

Aug 16, 2012, 7:51 AM

Post #32 of 35 (1776 views)
Re: [gerble1000] i have an emergency please help [In reply to] Can't Post

The "junk code" you refer to is the png image.

I'm not going to get involved in your php coding, other than to suggest adding an exit(0) statement at the end;


gerble1000
User

Aug 16, 2012, 7:57 AM

Post #33 of 35 (1774 views)
Re: [FishMonger] i have an emergency please help [In reply to] Can't Post

ok i have added the exit code and it still does the same. why would it be showing the junk code anyway


FishMonger
Veteran / Moderator

Aug 16, 2012, 8:05 AM

Post #34 of 35 (1772 views)
Re: [gerble1000] i have an emergency please help [In reply to] Can't Post

Because that's what the last section of code tells it to do.


gerble1000
User

Aug 16, 2012, 8:26 AM

Post #35 of 35 (1770 views)
Re: [FishMonger] i have an emergency please help [In reply to] Can't Post

your a genius i got it.
i removed the Imagepng($res);
at the end of the php code and that stopped it trying to output the image as all i wanted to do was to save the file.png to folder.
now all i had to do with the script was to add php to the system command and now it all works.
now time to start with using loops in that awfull script.
thankyou fishmonger :)

 
 


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives