Velocity Reviews

Velocity Reviews (http://www.velocityreviews.com/forums/index.php)
-   Perl Misc (http://www.velocityreviews.com/forums/f67-perl-misc.html)
-   -   how to use system call within a cgi script (http://www.velocityreviews.com/forums/t908617-how-to-use-system-call-within-a-cgi-script.html)

ReggieC 10-10-2008 08:41 PM

how to use system call within a cgi script
 
Hi there,

I have to execute an executable from a CGI script written in perl. I
cannot do that even
with a very simple test like:
$result = system("mkdir test1");
$result = system("mkdir ", "test1");
exec('mkdir test1');
but always got 500 Internal Service Error.

Adding $ENV{"PATH"} = ""; and use full path of mkdir did not help.

I'm using perl 5.8 with Apache 2.2.

Any opinion is very much appreciated.

Jürgen Exner 10-10-2008 08:54 PM

Re: how to use system call within a cgi script
 
ReggieC <ktrchang@gmail.com> wrote:
>Hi there,
>
>I have to execute an executable from a CGI script written in perl. I
>cannot do that even
>with a very simple test like:
>$result = system("mkdir test1");
>$result = system("mkdir ", "test1");
>exec('mkdir test1');
>but always got 500 Internal Service Error.


What does the server log tell you?

>Adding $ENV{"PATH"} = ""; and use full path of mkdir did not help.
>I'm using perl 5.8 with Apache 2.2.
>Any opinion is very much appreciated.


Could be many, many, many things. Missing permissions, wrong path,
virtual root folder, ...

See 'perldoc -q 500' for some ideas.

jue

smallpond 10-10-2008 08:57 PM

Re: how to use system call within a cgi script
 
On Oct 10, 4:41 pm, ReggieC <ktrch...@gmail.com> wrote:
> Hi there,
>
> I have to execute an executable from a CGI script written in perl. I
> cannot do that even
> with a very simple test like:
> $result = system("mkdir test1");
> $result = system("mkdir ", "test1");
> exec('mkdir test1');
> but always got 500 Internal Service Error.
>
> Adding $ENV{"PATH"} = ""; and use full path of mkdir did not help.
>
> I'm using perl 5.8 with Apache 2.2.
>
> Any opinion is very much appreciated.


What is the permission and owner on the directory where you are
trying
to make a new subdirectory and what user are you running as?


Jamie 10-10-2008 09:39 PM

Re: how to use system call within a cgi script
 
In <116bd205-830c-47ce-8605-731d6340b1d5@x16g2000prn.googlegroups.com>,
ReggieC <ktrchang@gmail.com> mentions:
>Hi there,
>
>I have to execute an executable from a CGI script written in perl. I
>cannot do that even
>with a very simple test like:
>$result = system("mkdir test1");
>$result = system("mkdir ", "test1");
>exec('mkdir test1');
>but always got 500 Internal Service Error.
>
>Adding $ENV{"PATH"} = ""; and use full path of mkdir did not help.
>
>I'm using perl 5.8 with Apache 2.2.
>
>Any opinion is very much appreciated.


Print out a header first so you can see the problem? Also, try redirecting
stderr to see any error messages.

In "production", I often use system in a list context:

system('/bin/mkdir','path1');

You probably don't want it evaluated by the shell.

Most likely it's a permissions issue.

Jamie
--
http://www.geniegate.com Custom web programming
Perl * Java * UNIX User Management Solutions

ReggieC 10-10-2008 10:46 PM

Re: how to use system call within a cgi script
 
Thanks for info from Jue and Smallpond.

Basically the key is $ENV{"PATH"}="";

After I carefully checked, I missed to declare my $result after
adding $ENV{"PATH"}=""; (I modified and moved lined around
while testing. When I did not have $ENV{"PATH"}=""; I did
have my $result.)

Thanks a lot for the tip of checking logs. The info there tipped
me up. Knowing perldoc -q 500 is useful, too.

Thanks again.


smallpond wrote:
> On Oct 10, 4:41 pm, ReggieC <ktrch...@gmail.com> wrote:
> > Hi there,
> >
> > I have to execute an executable from a CGI script written in perl. I
> > cannot do that even
> > with a very simple test like:
> > $result = system("mkdir test1");
> > $result = system("mkdir ", "test1");
> > exec('mkdir test1');
> > but always got 500 Internal Service Error.
> >
> > Adding $ENV{"PATH"} = ""; and use full path of mkdir did not help.
> >
> > I'm using perl 5.8 with Apache 2.2.
> >
> > Any opinion is very much appreciated.

>
> What is the permission and owner on the directory where you are
> trying
> to make a new subdirectory and what user are you running as?


Tony Curtis 10-11-2008 02:59 PM

Re: how to use system call within a cgi script
 
ReggieC wrote:
> Hi there,
>
> I have to execute an executable from a CGI script written in perl. I
> cannot do that even
> with a very simple test like:
> $result = system("mkdir test1");
> $result = system("mkdir ", "test1");
> exec('mkdir test1');
> but always got 500 Internal Service Error.


why would you want to go out to a shell for a perl built-in?

perldoc -f mkdir

hth
t

John Bokma 10-11-2008 11:25 PM

Re: how to use system call within a cgi script
 
ReggieC <ktrchang@gmail.com> wrote:

> Hi there,
>
> I have to execute an executable from a CGI script written in perl. I
> cannot do that even
> with a very simple test like:
> $result = system("mkdir test1");
> $result = system("mkdir ", "test1");
> exec('mkdir test1');


Read perldoc -f exec

Remove the exec, and try again, does it now work?

> but always got 500 Internal Service Error.


Always copy error messages, don't type them yourself.

--
John http://johnbokma.com/ - Hacking & Hiking in Mexico

Perl help in exchange for a gift:
http://johnbokma.com/perl/help-in-ex...or-a-gift.html

Grant 10-12-2008 12:29 AM

Re: how to use system call within a cgi script
 
On 11 Oct 2008 23:25:58 GMT, John Bokma <john@castleamber.com> wrote:

>ReggieC <ktrchang@gmail.com> wrote:
>
>> Hi there,
>>
>> I have to execute an executable from a CGI script written in perl. I
>> cannot do that even
>> with a very simple test like:
>> $result = system("mkdir test1");
>> $result = system("mkdir ", "test1");
>> exec('mkdir test1');

>
>Read perldoc -f exec
>
>Remove the exec, and try again, does it now work?
>
>> but always got 500 Internal Service Error.

>
>Always copy error messages, don't type them yourself.


I'd add to that, tail -f the error_log in another terminal and make sure
you made the work area world writable -- not particularly safe, is it?

Grant.
--
http://bugsplatter.id.au/

Grant 10-12-2008 12:38 AM

Re: how to use system call within a cgi script
 
On 11 Oct 2008 23:25:58 GMT, John Bokma <john@castleamber.com> wrote:

>ReggieC <ktrchang@gmail.com> wrote:
>
>> Hi there,
>>
>> I have to execute an executable from a CGI script written in perl. I
>> cannot do that even
>> with a very simple test like:
>> $result = system("mkdir test1");
>> $result = system("mkdir ", "test1");
>> exec('mkdir test1');

>
>Read perldoc -f exec
>
>Remove the exec, and try again, does it now work?
>
>> but always got 500 Internal Service Error.

>
>Always copy error messages, don't type them yourself.


Oops, I meant to add an example, this is from a .cgi here (awk):
....
# create a unique output filename
cmd = "mktemp public/cc2ip.XXXXXX"; cmd | getline out; close(cmd)

# make the output filename world writable and append .txt
system("touch " out " && chmod a+rw " out " && mv " out " " out ".txt")
out = out ".txt"
....

The matching web directory:
-r-sr-xr-x 1 grant wheel 3104 2008-10-05 09:07 cc2ip.cgi*
-rwxrwxr-x 1 grant wheel 11570 2008-10-12 06:35 index.html*
-rwxrwxr-x 1 grant wheel 444 2008-10-05 09:07 lookup-ip*
drwxrwxrwx 2 grant wheel 184 2008-10-12 00:02 public/
drwx-w---- 2 grant wheel 128 2008-10-12 11:32 server/

Access to the server script and directory is restricted by a security
wrapper written in C.

Context: http://bugsplatter.id.au/cc2ip/

Grant.
--
http://bugsplatter.id.au/

Tim Greer 10-14-2008 07:24 PM

Re: how to use system call within a cgi script
 
Grant wrote:

> On 11 Oct 2008 23:25:58 GMT, John Bokma <john@castleamber.com> wrote:
>
>>ReggieC <ktrchang@gmail.com> wrote:
>>
>>> Hi there,
>>>
>>> I have to execute an executable from a CGI script written in perl.
>>> I cannot do that even
>>> with a very simple test like:
>>> $result = system("mkdir test1");
>>> $result = system("mkdir ", "test1");
>>> exec('mkdir test1');

>>
>>Read perldoc -f exec
>>
>>Remove the exec, and try again, does it now work?
>>
>>> but always got 500 Internal Service Error.

>>
>>Always copy error messages, don't type them yourself.

>
> Oops, I meant to add an example, this is from a .cgi here (awk):
> ...
> # create a unique output filename
> cmd = "mktemp public/cc2ip.XXXXXX"; cmd | getline out;
> close(cmd)
>
> # make the output filename world writable and append .txt
> system("touch " out " && chmod a+rw " out " && mv " out " "
> out ".txt") out = out ".txt"
> ...


You probably don't want to make it world writable unless you have a good
reason, assuming they even need that those of permissions.


>
> The matching web directory:
> -r-sr-xr-x 1 grant wheel 3104 2008-10-05 09:07 cc2ip.cgi*
> -rwxrwxr-x 1 grant wheel 11570 2008-10-12 06:35 index.html*
> -rwxrwxr-x 1 grant wheel 444 2008-10-05 09:07 lookup-ip*
> drwxrwxrwx 2 grant wheel 184 2008-10-12 00:02 public/
> drwx-w---- 2 grant wheel 128 2008-10-12 11:32 server/


Glad to see nothing is setguid there.

World write is indeed sometimes needed for some people, and is fine if
they aren't on a shared server, but I'd just recommend against it if
you're on a server that other users are on.

Anyway, yeah, just check the logs, print the proper header for CGI and
be sure to check your calls and catch (and log or report) any
errors/failures.
--
Tim Greer, CEO/Founder/CTO, BurlyHost.com, Inc.
Shared Hosting, Reseller Hosting, Dedicated & Semi-Dedicated servers
and Custom Hosting. 24/7 support, 30 day guarantee, secure servers.
Industry's most experienced staff! -- Web Hosting With Muscle!


All times are GMT. The time now is 09:15 PM.

Powered by vBulletin®. Copyright ©2000 - 2013, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.


1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57