Perl Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsProgramming LanguagesPerl Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
Stop making mediocre tutorials.The best tutorials are video! Camtasia Studio makes it easy to create engaging, buzz-building screen videos at any size, in any popular format. Download the free trial!
  #1  
Old April 18th, 2008, 07:39 AM
cowboyroy cowboyroy is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Oct 2006
Posts: 62 cowboyroy User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 18 h 3 m 2 sec
Reputation Power: 2
Cgi - system command and redirecting

HI

I have a perl cgi that does everything i want, now im at the end of it and I want it to run a shell script and then redirect the user to another page.

I have tried looking in the system and exec calls but can't get either to work and am not even sure which is the best one to use.
If someone can provide me some simple syntax for how to execute a file that i would normally do like this:
# ./myscriptname
I would be most greatful.

Once it runs myscript I then need the user to be redirected to a page example.htm
I have tried
print "location: path/to/example.htm"; but it only seems to work when put at the top of the cgi, this is no good as the cgi validates a form (it doesnt when you put this at the top)

Alternatively to this the cgi could generate its own html...

At the moment my script looks like this (excluding the usual stuff at the top)

perl Code:
Original - perl Code
  1. validation();
  2. if ($status == 0)
  3. {
  4. print "Please go back and correct the mistakes \n";
  5.  die;
  6. }
  7. else
  8. {
  9. go();
  10. }


I need the things i detailed above to happen after the go subroutine.

THanks !

Reply With Quote
  #2  
Old April 18th, 2008, 09:40 AM
vb.net vb.net is offline
Demonic Swordsman DGQB
Dev Shed Novice (500 - 999 posts)
 
Join Date: Apr 2003
Posts: 974 vb.net User rank is Second Lieutenant (5000 - 10000 Reputation Level)vb.net User rank is Second Lieutenant (5000 - 10000 Reputation Level)vb.net User rank is Second Lieutenant (5000 - 10000 Reputation Level)vb.net User rank is Second Lieutenant (5000 - 10000 Reputation Level)vb.net User rank is Second Lieutenant (5000 - 10000 Reputation Level)vb.net User rank is Second Lieutenant (5000 - 10000 Reputation Level)vb.net User rank is Second Lieutenant (5000 - 10000 Reputation Level) 
Time spent in forums: 3 Days 7 h 46 m 20 sec
Reputation Power: 76
You could possibly try it using Javascript. Here is an example: http://www.w3schools.com/JS/tryit.asp?filename=tryjs_location

So you'd end up with something like this:

perl Code:
Original - perl Code
  1. validation();
  2. if ($status == 0)
  3. {
  4. print "Please go back and correct the mistakes \n";
  5.  die;
  6. }
  7. else
  8. {
  9. print "<script>// change url here</script>";
  10. }

Reply With Quote
  #3  
Old April 20th, 2008, 06:49 AM
Axweildr's Avatar
Axweildr Axweildr is offline
CPAN medic ...
Click here for more information.
 
Join Date: Mar 2003
Location: Location: Location:
Posts: 10,905 Axweildr User rank is General 20th Grade (Above 100000 Reputation Level)Axweildr User rank is General 20th Grade (Above 100000 Reputation Level)Axweildr User rank is General 20th Grade (Above 100000 Reputation Level)Axweildr User rank is General 20th Grade (Above 100000 Reputation Level)Axweildr User rank is General 20th Grade (Above 100000 Reputation Level)Axweildr User rank is General 20th Grade (Above 100000 Reputation Level)Axweildr User rank is General 20th Grade (Above 100000 Reputation Level)Axweildr User rank is General 20th Grade (Above 100000 Reputation Level)Axweildr User rank is General 20th Grade (Above 100000 Reputation Level)Axweildr User rank is General 20th Grade (Above 100000 Reputation Level)Axweildr User rank is General 20th Grade (Above 100000 Reputation Level)Axweildr User rank is General 20th Grade (Above 100000 Reputation Level)Axweildr User rank is General 20th Grade (Above 100000 Reputation Level)Axweildr User rank is General 20th Grade (Above 100000 Reputation Level)Axweildr User rank is General 20th Grade (Above 100000 Reputation Level)Axweildr User rank is General 20th Grade (Above 100000 Reputation Level)  Folding Points: 119844 Folding Title: Super Ultimate Folder - Level 1Folding Points: 119844 Folding Title: Super Ultimate Folder - Level 1Folding Points: 119844 Folding Title: Super Ultimate Folder - Level 1Folding Points: 119844 Folding Title: Super Ultimate Folder - Level 1Folding Points: 119844 Folding Title: Super Ultimate Folder - Level 1Folding Points: 119844 Folding Title: Super Ultimate Folder - Level 1
Time spent in forums: 3 Months 3 Weeks 6 Days 3 h 56 m 58 sec
Reputation Power: 2304
Send a message via Google Talk to Axweildr
Orkut
the location redirect will only work if it's the 'first' thing printed to the browser...
__________________
--Ax
without exception, there is no rule ...
The great thing about Object Oriented code is that it can make small, simple problems look like large, complex ones


09 F9 11 02
9D 74 E3 5B
D8 41 56 C5
63 56 88 C0
Some people, when confronted with a problem, think "I know, I'll use regular expressions." Now they have two problems.
-- Jamie Zawinski

Reply With Quote
  #4  
Old April 21st, 2008, 08:32 AM
cowboyroy cowboyroy is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Oct 2006
Posts: 62 cowboyroy User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 18 h 3 m 2 sec
Reputation Power: 2
cheers for the replies. I have found a rather skanky way of doing it - generating my own html which then uses a meta refresh / redirect, but I may just generate my own html without redirecting as it doesn't need to be anything special.

now... Does anyone have any idea how i would run a shell script from within my cgi script.
I think I want to use 'system' as it does it then returns back to the cgi to carry on.
I don't need any output from the script - i just want it to run but I just cant get it to work.

Reply With Quote
  #5  
Old April 21st, 2008, 06:52 PM
Axweildr's Avatar
Axweildr Axweildr is offline
CPAN medic ...
Click here for more information.
 
Join Date: Mar 2003
Location: Location: Location:
Posts: 10,905 Axweildr User rank is General 20th Grade (Above 100000 Reputation Level)Axweildr User rank is General 20th Grade (Above 100000 Reputation Level)Axweildr User rank is General 20th Grade (Above 100000 Reputation Level)Axweildr User rank is General 20th Grade (Above 100000 Reputation Level)Axweildr User rank is General 20th Grade (Above 100000 Reputation Level)Axweildr User rank is General 20th Grade (Above 100000 Reputation Level)Axweildr User rank is General 20th Grade (Above 100000 Reputation Level)Axweildr User rank is General 20th Grade (Above 100000 Reputation Level)Axweildr User rank is General 20th Grade (Above 100000 Reputation Level)Axweildr User rank is General 20th Grade (Above 100000 Reputation Level)Axweildr User rank is General 20th Grade (Above 100000 Reputation Level)Axweildr User rank is General 20th Grade (Above 100000 Reputation Level)Axweildr User rank is General 20th Grade (Above 100000 Reputation Level)Axweildr User rank is General 20th Grade (Above 100000 Reputation Level)Axweildr User rank is General 20th Grade (Above 100000 Reputation Level)Axweildr User rank is General 20th Grade (Above 100000 Reputation Level)  Folding Points: 119844 Folding Title: Super Ultimate Folder - Level 1Folding Points: 119844 Folding Title: Super Ultimate Folder - Level 1Folding Points: 119844 Folding Title: Super Ultimate Folder - Level 1Folding Points: 119844 Folding Title: Super Ultimate Folder - Level 1Folding Points: 119844 Folding Title: Super Ultimate Folder - Level 1Folding Points: 119844 Folding Title: Super Ultimate Folder - Level 1
Time spent in forums: 3 Months 3 Weeks 6 Days 3 h 56 m 58 sec
Reputation Power: 2304
Send a message via Google Talk to Axweildr
Orkut
what have you tried?

Reply With Quote
  #6  
Old April 22nd, 2008, 03:37 AM
cowboyroy cowboyroy is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Oct 2006
Posts: 62 cowboyroy User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 18 h 3 m 2 sec
Reputation Power: 2
Quote:
Originally Posted by Axweildr
what have you tried?


At the moment i have this line of code

perl Code:
Original - perl Code
  1. system("/var/www/cgi-bin/myfolder/myscript") == 0 or die "error ! $?;


As far as I know there is nothing wrong with that and since my last post i have come to think it must be something to do with folder /file permissions.

Firstly, should i chown myscript to apache?
myscript also puts a file in to a different folder - /var/www/html/download - does the download folder need to be chowned to apache? I have write / execute permissions set for both so that shouldnt be a problem.

Reply With Quote
  #7  
Old April 22nd, 2008, 12:24 PM
Axweildr's Avatar
Axweildr Axweildr is offline
CPAN medic ...
Click here for more information.
 
Join Date: Mar 2003
Location: Location: Location:
Posts: 10,905 Axweildr User rank is General 20th Grade (Above 100000 Reputation Level)Axweildr User rank is General 20th Grade (Above 100000 Reputation Level)Axweildr User rank is General 20th Grade (Above 100000 Reputation Level)Axweildr User rank is General 20th Grade (Above 100000 Reputation Level)Axweildr User rank is General 20th Grade (Above 100000 Reputation Level)Axweildr User rank is General 20th Grade (Above 100000 Reputation Level)Axweildr User rank is General 20th Grade (Above 100000 Reputation Level)Axweildr User rank is General 20th Grade (Above 100000 Reputation Level)Axweildr User rank is General 20th Grade (Above 100000 Reputation Level)Axweildr User rank is General 20th Grade (Above 100000 Reputation Level)Axweildr User rank is General 20th Grade (Above 100000 Reputation Level)Axweildr User rank is General 20th Grade (Above 100000 Reputation Level)Axweildr User rank is General 20th Grade (Above 100000 Reputation Level)Axweildr User rank is General 20th Grade (Above 100000 Reputation Level)Axweildr User rank is General 20th Grade (Above 100000 Reputation Level)Axweildr User rank is General 20th Grade (Above 100000 Reputation Level)  Folding Points: 119844 Folding Title: Super Ultimate Folder - Level 1Folding Points: 119844 Folding Title: Super Ultimate Folder - Level 1Folding Points: 119844 Folding Title: Super Ultimate Folder - Level 1Folding Points: 119844 Folding Title: Super Ultimate Folder - Level 1Folding Points: 119844 Folding Title: Super Ultimate Folder - Level 1Folding Points: 119844 Folding Title: Super Ultimate Folder - Level 1
Time spent in forums: 3 Months 3 Weeks 6 Days 3 h 56 m 58 sec
Reputation Power: 2304
Send a message via Google Talk to Axweildr
Orkut
you need to pass the path to perl

perl Code:
Original - perl Code
  1. system("/usr/bin/perl /var/www/cgi-bin/myfolder/myscript") or die "error $!|$?";

Reply With Quote
  #8  
Old April 24th, 2008, 06:11 AM
cowboyroy cowboyroy is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Oct 2006
Posts: 62 cowboyroy User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 18 h 3 m 2 sec
Reputation Power: 2
Its a shell script not a perl script - do i still need to do that?
I noticed that you included $! and Thats given me a better error message

"inappropriate ioctl for device"
$? is giving me the error message 0

Is this because my shell script wants to print something to the terminal ? and to make things more complicated... my shell script calls another one which also wants to write things to the terminal..

HELP !


Reply With Quote
  #9  
Old April 24th, 2008, 12:22 PM
Axweildr's Avatar
Axweildr Axweildr is offline
CPAN medic ...
Click here for more information.
 
Join Date: Mar 2003
Location: Location: Location:
Posts: 10,905 Axweildr User rank is General 20th Grade (Above 100000 Reputation Level)Axweildr User rank is General 20th Grade (Above 100000 Reputation Level)Axweildr User rank is General 20th Grade (Above 100000 Reputation Level)Axweildr User rank is General 20th Grade (Above 100000 Reputation Level)Axweildr User rank is General 20th Grade (Above 100000 Reputation Level)Axweildr User rank is General 20th Grade (Above 100000 Reputation Level)Axweildr User rank is General 20th Grade (Above 100000 Reputation Level)Axweildr User rank is General 20th Grade (Above 100000 Reputation Level)Axweildr User rank is General 20th Grade (Above 100000 Reputation Level)Axweildr User rank is General 20th Grade (Above 100000 Reputation Level)Axweildr User rank is General 20th Grade (Above 100000 Reputation Level)Axweildr User rank is General 20th Grade (Above 100000 Reputation Level)Axweildr User rank is General 20th Grade (Above 100000 Reputation Level)Axweildr User rank is General 20th Grade (Above 100000 Reputation Level)Axweildr User rank is General 20th Grade (Above 100000 Reputation Level)Axweildr User rank is General 20th Grade (Above 100000 Reputation Level)  Folding Points: 119844 Folding Title: Super Ultimate Folder - Level 1Folding Points: 119844 Folding Title: Super Ultimate Folder - Level 1Folding Points: 119844 Folding Title: Super Ultimate Folder - Level 1Folding Points: 119844 Folding Title: Super Ultimate Folder - Level 1Folding Points: 119844 Folding Title: Super Ultimate Folder - Level 1Folding Points: 119844 Folding Title: Super Ultimate Folder - Level 1
Time spent in forums: 3 Months 3 Weeks 6 Days 3 h 56 m 58 sec
Reputation Power: 2304
Send a message via Google Talk to Axweildr
Orkut
have a wise look at your shell scripts and see how much is involved in porting them to perl, otherwise you'd need to enable permissions which wouldn't be a good idea

Reply With Quote
  #10  
Old April 29th, 2008, 04:32 AM
cowboyroy cowboyroy is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Oct 2006
Posts: 62 cowboyroy User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 18 h 3 m 2 sec
Reputation Power: 2
I have put some of it in to perl but some of my stuff just had to stay in the shell script..
my error message disappeared and looking through my apache logs I found out there were also permissions problems so I chowned a few folders to apache and it now works.

now to get stuck on the next bit

Reply With Quote
  #11  
Old April 29th, 2008, 04:36 AM
Axweildr's Avatar
Axweildr Axweildr is offline
CPAN medic ...
Click here for more information.
 
Join Date: Mar 2003
Location: Location: Location:
Posts: 10,905 Axweildr User rank is General 20th Grade (Above 100000 Reputation Level)Axweildr User rank is General 20th Grade (Above 100000 Reputation Level)Axweildr User rank is General 20th Grade (Above 100000 Reputation Level)Axweildr User rank is General 20th Grade (Above 100000 Reputation Level)Axweildr User rank is General 20th Grade (Above 100000 Reputation Level)Axweildr User rank is General 20th Grade (Above 100000 Reputation Level)Axweildr User rank is General 20th Grade (Above 100000 Reputation Level)Axweildr User rank is General 20th Grade (Above 100000 Reputation Level)Axweildr User rank is General 20th Grade (Above 100000 Reputation Level)Axweildr User rank is General 20th Grade (Above 100000 Reputation Level)Axweildr User rank is General 20th Grade (Above 100000 Reputation Level)Axweildr User rank is General 20th Grade (Above 100000 Reputation Level)Axweildr User rank is General 20th Grade (Above 100000 Reputation Level)Axweildr User rank is General 20th Grade (Above 100000 Reputation Level)Axweildr User rank is General 20th Grade (Above 100000 Reputation Level)Axweildr User rank is General 20th Grade (Above 100000 Reputation Level)  Folding Points: 119844 Folding Title: Super Ultimate Folder - Level 1Folding Points: 119844 Folding Title: Super Ultimate Folder - Level 1Folding Points: 119844 Folding Title: Super Ultimate Folder - Level 1Folding Points: 119844 Folding Title: Super Ultimate Folder - Level 1Folding Points: 119844 Folding Title: Super Ultimate Folder - Level 1Folding Points: 119844 Folding Title: Super Ultimate Folder - Level 1
Time spent in forums: 3 Months 3 Weeks 6 Days 3 h 56 m 58 sec
Reputation Power: 2304
Send a message via Google Talk to Axweildr
Orkut
good stuff.

Reply With Quote
Reply

Viewing: