LinuxQuestions.org
Latest LQ Deal: Complete CCNA, CCNP & Red Hat Certification Training Bundle
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 10-28-2014, 02:40 AM   #1
zak100
Member
 
Registered: Jul 2009
Posts: 225

Rep: Reputation: 2
windows file cannot execute on shell


Hi,
I created a perl file on windows but when i am trying to retrieve that file on unix(fedora20) and trying to execute it on the shell prompt, i am getting following error:
Code:
[root@localhost cgi]# ./adminform2_windows.pl
bash: ./adminform2_windows.pl: /usr/bin/perl^M: bad interpreter: No such file or directory
[root@localhost cgi]# ls
The code is:

Code:
[root@localhost cgi]# cat adminform2_windows.pl
#!/usr/bin/perl

#NOTE This code has got prolem with session management
use CGI qw(:standard);
use CGI::Session;
use DBI;
my $ID;
my $Name;
my $Phone;

$cgi = new CGI;

my $session = new CGI::Session(undef, $cgi, {Directory=>'/tmp'});
        
#$cookie = $cgi->cookie(CGISESSID => $session->id );
#print $cgi->header(-cookie=>$cookie);


print "Content-type: text/html\n\n";
print <<HTML_PAGE;

<html>
<head>
<title>Admin Page: Display Records,Edit, Delete and Insert</title>
</head>
<body>

<FORM method="post" action="/cgi-bin/insertbyAdmin.pl">
<TABLE BORDER ="0">
<TR>    
<TD>Name</TD>
<TD><input type="text" name="Name" value=""></TD>
</TR>
<TR>
<TD>Phone </TD> 
<TD><input type="text" name="Phone" value=""></TD>
</TR>
<TR>
<TD><h1>Insert Next Record: Select Yes or No</h1></TD></TR>
<TR>    
<TD><li> <INPUT TYPE="radio" NAME="Yes" value="Yes" unchecked> Yes </TD>
</TR>
<TR>    
<TD><li> <INPUT TYPE="radio" NAME="No" value="No.Return to Login" unchecked> No </TD>
</TR>
<TR><TD COLSPAN="2" ALIGN="RIGHT">
<input type="submit" name="submit" value="insertNext">   
</TD></TR></TABLE></FORM>

#$ID = $cgi->param( 'ID' ) || '';
$Name = $cgi->param ('Name') || '';
$Phone = $cgi->param( 'Phone' ) || '';

$session->param(name1, $Name);
$session->param(Phone1, $Phone);
#$session->param(semester_, $semester);

<form method ="post" action="/cgi-bin/radioeditordelete.pl">
<TABLE BORDER ="0">
<TR><TD><input type="submit" name="EditDelete" value="EditDeleteRecord">    </TD></TR>
<TD><li> <INPUT TYPE="radio" NAME="EditDelete" value="Edit" unchecked> Edit </TD>
<TD> ID: </TD>
<TD> <input type="text" name="ID1" value=""></TD>
</TR>
<TR>
<TD><li> <INPUT TYPE="radio" NAME="EditDelete" value="Delete" unchecked> Delete</TD>
<TD> ID: </TD>
<TD> <input type="text" name="ID1" value=""></TD>
</TR>
</TABLE></FORM>
HTML_PAGE


$dbh = DBI->connect("dbi:mysql:test", 'root','') or die "Unable to connect: $DBI::errstr\n";
## query the database
	$sth = $dbh->prepare("SELECT * FROM samples");
$sth->execute();
print <<HTML_PAGE;
<table>
	<tr>
	<th>ID</th>
	<th>Name</th>
	<th>Phone</th>
	</tr>

HTML_PAGE
while($row = $sth->fetchrow_hashref) {
#$first_name = chop($row->{first_name});
#$surname= chop($row->{surname});
#$email = cho($row->{email});
#print "<tr><td>" . $first_name . "</td> </tr>&nbsp;";
#print "<tr><td>" . $surname . "</td> </tr>&nbsp;";
#print "<tr><td>" . $email . "</td></tr> &nbsp;";
print "<td>$row->{ID}</td> &nbsp;";
print "<td>$row->{Name}</td> &nbsp;";
print "<td>$row->{Phone}</td></tr> &nbsp;";
print "<br>";
}
print <<HTML;
</table>
</BODY></HTML>
HTML
[root@localhost cgi]#
I have written the whole code on Linux as 'admin2.pl' and its working.
Code:
[root@localhost cgi]# cat admin2.pl
#!/usr/bin/perl
print "Content-type: text/html\n\n";
use CGI;
use CGI::Session;
use DBI;
my $ID;
my $Name;
my $Phone;
my $cgi;
my $session;
my $cookie;
my $sth;
my $dbh;
my $row;

$cgi = new CGI;
$session = new CGI::Session(undef, $cgi, {Directory=>'/tmp'});
$cookie = $cgi->cookie(CGISESSID => $session->id);

print <<HTML_PAGE;
<html>
<head>
<title>Admin Page: Display Records, Edit, Delete and Insert </title>
</head>
<body>

<FORM method = "post" action="/cgi-bin/insertbyAdmin.pl">
<TABLE BORDER ="0">
<TR>
<TD>Name</TD>
<TD><input type="text" name="Name" value=""></TD>
</TR>
<TR>
<TD>Phone</TD>
<TD><input type ="text" name="Phone" value=""></TD>
</TR>
<TR>
<TD><h1>Insert Next Record: Select Yes or No </h1></TD></TR>
</TR>
<TR>
<TD><li><Input Type="radio" name="Yes" value="Yes" unchecked>Yes </TD>
</TR>
<TR>
<TD><li><INPUT TYPE="radio" name="No" value="No. Return to Login" unchecked>No</TD>
</TR>
<TR><TD COLSPAN="2" ALIGN="RIGHT">
<input type="submit" name="submit" value="insertNext">
</TD></TR></TABLE></FORM>
HTML_PAGE

$Phone = $cgi->param('Phone') || '';
$Name = $cgi->param('Name') || '';

$session->param(name1, $Name);
$session->param(Phone1, $Phone);

print<<HTML_PAGE;
<FORM method = "post" action="/cgi-bin/radioeditordelet.pl">
<TABLE BORDER ="0">
<TR><TD><input type="submit" name="EditDelete" value ="EditDeleteRecord"></TD></TR>
<TD><li><INPUT TYPE ="radio" Name="EidtDelete" value="Edit" unchecked>Edit</TD>
<TD>ID: </TD>
<TD><input type="text" name="ID1" value=""</TD>
</TR>
<TD><li><INPUT TYPE ="radio" Name="EidtDelete" value="Delete" unchecked>Delete</TD>
<TD>ID: </TD>
<TD><input type="text" name="ID2" value=""</TD>
</TR>
</TABLE></FORM>
HTML_PAGE


$dbh = DBI->connect("dbi:mysql:test",'root','') or die "unable to connect: $DBI::errstr\n";
$sth= $dbh->prepare("Select * from samples");
$sth->execute();

print<<HTML_PAGE;
<table>
<tr>
<th>ID</th>
<th>Name</th>
<th>Phone</th>
</tr>
HTML_PAGE

while($row = $sth->fetchrow_hashref){
print "<tr><td>$row->{ID}</td> &nbsp;";
print "<td>$row->{Name}</td> &nbsp;";
print "<td>$row->{Phone}</td></tr> &nbsp;";
print "<br>";

}
print<<HTML_PAGE;
</table>
</BODY></HTML>
HTML_PAGE
exit;




[root@localhost cgi]# ./admin2.pl
Content-type: text/html

<html>
<head>
<title>Admin Page: Display Records, Edit, Delete and Insert </title>
</head>
<body>

<FORM method = "post" action="/cgi-bin/insertbyAdmin.pl">
<TABLE BORDER ="0">
<TR>
<TD>Name</TD>
<TD><input type="text" name="Name" value=""></TD>
</TR>
<TR>
<TD>Phone</TD>
<TD><input type ="text" name="Phone" value=""></TD>
</TR>
<TR>
<TD><h1>Insert Next Record: Select Yes or No </h1></TD></TR>
</TR>
<TR>
<TD><li><Input Type="radio" name="Yes" value="Yes" unchecked>Yes </TD>
</TR>
<TR>
<TD><li><INPUT TYPE="radio" name="No" value="No. Return to Login" unchecked>No</TD>
</TR>
<TR><TD COLSPAN="2" ALIGN="RIGHT">
<input type="submit" name="submit" value="insertNext">
</TD></TR></TABLE></FORM>
<FORM method = "post" action="/cgi-bin/radioeditordelet.pl">
<TABLE BORDER ="0">
<TR><TD><input type="submit" name="EditDelete" value ="EditDeleteRecord"></TD></TR>
<TD><li><INPUT TYPE ="radio" Name="EidtDelete" value="Edit" unchecked>Edit</TD>
<TD>ID: </TD>
<TD><input type="text" name="ID1" value=""</TD>
</TR>
<TD><li><INPUT TYPE ="radio" Name="EidtDelete" value="Delete" unchecked>Delete</TD>
<TD>ID: </TD>
<TD><input type="text" name="ID2" value=""</TD>
</TR>
</TABLE></FORM>
<table>
<tr>
<th>ID</th>
<th>Name</th>
<th>Phone</th>
</tr>
<tr><td>1</td> &nbsp;<td>abc</td> &nbsp;<td>555-5555</td></tr> &nbsp;<br><tr><td>2</td> &nbsp;<td>abcd3</td> &nbsp;<td>-1801</td></tr> &nbsp;<br><tr><td>3</td> &nbsp;<td>abcd4</td> &nbsp;<td>200-2002</td></tr> &nbsp;<br><tr><td>4</td> &nbsp;<td>abcd5</td> &nbsp;<td>200-2003</td></tr> &nbsp;<br><tr><td>5</td> &nbsp;<td>abcd6</td> &nbsp;<td>200-2004</td></tr> &nbsp;<br><tr><td>6</td> &nbsp;<td>abcd7</td> &nbsp;<td>200-2005</td></tr> &nbsp;<br></table>
</BODY></HTML>
[root@localhost cgi]#
Some body please guide me.


Zulfi.
 
Old 10-28-2014, 03:05 AM   #2
astrogeek
Moderator
 
Registered: Oct 2008
Distribution: Slackware [64]-X.{0|1|2|37|-current} ::12<=X<=14, FreeBSD_10{.0|.1|.2}
Posts: 4,028
Blog Entries: 1

Rep: Reputation: 2113Reputation: 2113Reputation: 2113Reputation: 2113Reputation: 2113Reputation: 2113Reputation: 2113Reputation: 2113Reputation: 2113Reputation: 2113Reputation: 2113
Code:
[root@localhost cgi]# ./adminform2_windows.pl
bash: ./adminform2_windows.pl: /usr/bin/perl^M: bad interpreter: No such file or directory
[root@localhost cgi]#
It looks like you have windows newlines in that file.

You may remove them with dos2unix (may not be on your system), by opening the file in vim, changing the file format and saving, or with a sed or awk script.
 
Old 10-28-2014, 03:05 PM   #3
John VV
LQ Muse
 
Registered: Aug 2005
Location: A2 area Mi.
Posts: 16,989

Rep: Reputation: 2447Reputation: 2447Reputation: 2447Reputation: 2447Reputation: 2447Reputation: 2447Reputation: 2447Reputation: 2447Reputation: 2447Reputation: 2447Reputation: 2447
as you are finding out
do not edit files on a windows computer

as above run "dos2unix" on the file

Code:
dos2unix -n adminform2_windows.pl adminform2_windowsNew.pl
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] Can't execute .sh file with shell konsole/installing slax to hdd Chazfem Slackware - Installation 2 01-07-2014 02:59 PM
Execute a shell script when clicking on a certain file extension antlarac Linux - Newbie 2 01-30-2013 10:55 AM
unable to execute a 4GE file in ksh shell gnagendr Programming 7 04-08-2010 02:56 AM
cannot execute script file from shell shahrahulb Linux - General 4 03-04-2008 08:02 AM
execute shell command inside of tcl file khucinx Programming 1 07-05-2004 02:29 PM


All times are GMT -5. The time now is 07:06 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration