Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

System Call in CGI script - Memory read error

Status
Not open for further replies.

ozcagc

Programmer
Mar 31, 2009
1
US
Hello,

I created a file upload webpage and what it is supposed to do is to take the file, run the C++ program in the server with a system call, and then return the result.

Before calling my own C++ program, I also created a simple "HelloWorld" program for testing purposes, which simply prints "Hello World" and some other strings.

But my main C++ program gets a file as an argument, reads it, print results to command prompt and files, creates many files and some output in the command window.

The relevant webpage is here: idefix.cs.rpi.edu/SpolGraph/SPOLGRAPH_RUN.html

The cgi code that is called when "Submit" button is clicked, is as follows:

Code:
#!C:\Perl\bin\perl.exe
use strict;
use DBI;
use File::Basename;
use CGI qw(:standard);
use CGI::Carp qw(fatalsToBrowser);
use Spreadsheet::WriteExcel;
require "cgi-lib.pl";

my $Directory = "C:\\wamp\\[URL unfurl="true"]www\\cgi";[/URL]
#my $Url_Path = "";

my $File_Name = param('inputfile');
my $email = param('email');
my $familyType = param('family');
my $graphType = param('graphType');
my $randomizer = param('randomizer');

my $File = Get_File_Name($File_Name);
my $FileNamerrr = 'C:\\wamp\\[URL unfurl="true"]www\\cgi\\supplyData434Small';[/URL]

$CGI::POST_MAX = 1024 * 2500; #2500 KB data is allowed

Store_Results();
Print_Results();

sub Get_File_Name
{
	if($ENV{HTTP_USER_AGENT} =~ /win/i)
	{
		fileparse_set_fstype("MSDOS");
	}
	elsif($ENV{HTTP_USER_AGENT} =~ /mac/i)
	{
		fileparse_set_fstype("MacOS");
	}
	
	my $full_name = shift;
	$full_name = basename($full_name);
	$full_name =~ s!\s!\_!g;
	
	return($full_name);
}

sub Store_Results
{
	my $data;
	my $mime = uploadInfo($File_Name)->{'Content-Type'};
	open(STORAGE, ">$Directory/$File") or die "Error: $Directory/$File: $!\n";
	if($mime !~ /text/)
	{
		binmode($File_Name);
		binmode(STORAGE);
	}
	
	while( read($File_Name, $data, 1024) )
	{
		print STORAGE $data;
	}
	
	close STORAGE;
}

sub Print_Results()
{
	print header;
	print qq(<PRE><B>File Name:</B> $File_Name\n);
	print qq(<PRE><B>File:</B> $File\n);
	print qq(<B>email:</B> $email\n);
	print qq(<B>Family Type:</B> $familyType\n);
	print qq(<B>Graph Type:</B> $graphType\n);
	print qq(<B>Randomizer:</B> $randomizer\n);
	#print qq(<B>File Contents:</B><XMP>\n\n);
	#while(<$File_Name>)
	#{
	#	print;
	#}
	#print qq($File_Name\t$email\t$familyType\t$graphType\t$randomizer\n);
	system('C:\Documents and Settings\Amina\Desktop\HelloWorld\debug\HelloWorld.exe', 'aaa');
	#system(cmd, '\c');
	#print qq($FileNamerrr \n);
	system('C:\Documents and Settings\Amina\Desktop\SpolGraph\debug\SpolGraph.exe', $FileNamerrr, $familyType, $graphType, $randomizer); #cmd, '\c'
	print qq(<XMP>);	
	print qq(</XMP></PRE>);
	print qq(<h3><font color="blue">Thank You for using SPOLGRAPH!</font></h3>);
	print qq(<p>Return to <a href="[URL unfurl="true"]http://cgi2.cs.rpi.edu/~ozcagc2/SPOLGRAPH.html">SPOLGRAPH[/URL] Home </a>);
	print qq(or <a href="[URL unfurl="true"]http://cgi2.cs.rpi.edu/~ozcagc2/SPOLGRAPH_RUN.html">Enter[/URL] another data</a></p>);
	print end_html;
}

Now, first system call for "HelloWorld.exe" works, the correct output is printed on the webpage.

The system call for "SpolGraph.exe" starts execution, goes up to some point, it prints some output to webpage, it even creates and partly fills files that it is supposed to fill in with values(I can check this on the folder of server side), but it always crashes. The output until the program crashes and error message returned in the server are as follows:

Output:
--------------------------------------------------------
Code:
File Name: supplyData434Small.txt
File: supplyData434Small.txt
email: ozcagc2@cs.rpi.edu
Family Type: CDC
Graph Type: Spoligotype
Randomizer: Seeded
Hello World Testerrrrr: aaabbb
C:\Documents and Settings\Amina\Desktop\SpolGraph\debug\SpolGraph.exe C:\wamp\[URL unfurl="true"]www\cgi\supplyData434Small[/URL] CDC Spoligotype Seeded 
Type something!!!
--------------------------------------------------------

Error message:
--------------------------------------------------------
Code:
The instruction at "0x004223db" referenced memory at "0xbae8ce97". The memory could not be "read".

Click on OK to terminate the program.
Click on CANCEL to debug the program.
--------------------------------------------------------

Now what is missing here? It is not because of the absolute path problem, I fixed it and that's how "HelloWorld" program works. So, what is the problem? I ran this "SpolGraph" program as a standalone application in various computers(both in server and client side), and they worked. But what is it now that causes this memory read error? I'm assuming I uploaded the file correctly, because I can see the uploaded file in the relevant folder in the server, and all that is need to be done is to run this "SpolGraph" program with the relevant system call in the code above. Any ideas are appreciated.

Thanks.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top