Hi
Unfortunately, the script still doesn't work.
A lot of output, so I've attached it into a logfile within this post.
Please take a look at it. If you'd like me to use a different version of Perl, please tell me which version.
Thanks in advance,
Panarchy
1) The deprecated split error was my fault, I forgot to change =~ back to =
2) You changed the <VNC.cpp> back. It should be <CPPTEMPLATE>.
3) I don't understand why some variables aren't getting initialized. I did it the long way (now it works), but it used to the other way before. Dunno, maybe they changed it in the newest release of Perl, which I updated to.
I don't know if this'll work because I don't have the compiler or linker installed on my system, but the rest seems to work just fine.
Code:#!/usr/bin/env perl use strict; use warnings; use POSIX; #declare whitespace-trimming function defined later sub trim($); my (@iplist,@hostlist,$template,$hostname,$currip,$currhost) = ((),(),'','','',''); #open ip list file open(IPFILE,"<iplist.csv") or die "Failed to open IP list file."; #read all lines into array my (@ipfile,$i,$total); @ipfile = <IPFILE>; #for each line in the ip file... $i = 0; $total = 0; foreach(@ipfile) { #strip leading and trailing spaces off the line my $thisline = $_; chomp($thisline); #use regular expressions to pull the ip address from the line. ($currhost,$currip) = split(/\,/,$thisline); #remove leading and trailing whitespace $hostlist[$i] = trim($currhost); $iplist[$i] = trim($currip); ++$i; ++$total; } #close ip list file close(IPFILE); #open template file open(CPPTEMPLATE,"<VNC.cpp") or die "Failed to open template file."; #for each ip address in the list... for($i = 0; $i < $total; ++$i) { #load entire file into single string... #undefine end-of-record variable, which is \n by default. this will result #in the file being divided up into an array of lines instead of one single #string like we want. undef $/; #read the file into $template. $template = <CPPTEMPLATE>; #reset $/ to avoid problems. $/ = "\n"; #get the current ip & host $currip = $iplist[$i]; $currhost = $hostlist[$i]; #open the output file open(CPPOUT,">$currhost.cpp") or die "Failed to open $currhost.cpp for writing."; #replace all instances of __PUTIPHERE__ in the template file with the #current ip address. $template =~ s/__PUTIPHERE__/$currip/g; #print the result to the output file. print CPPOUT $template; #close the output file close(CPPOUT); #compile `cl /clr $currhost.cpp`; `link super-resource.res main.obj /out:$currhost.exe`; #rewind to beginning of template file to read again seek(CPPTEMPLATE,0,SEEK_SET); } #close template file close(CPPTEMPLATE); #exit 1; #### sub trim($) { my $str = shift(@_); if(not defined $str){ return ''; } $str =~ s/^\s+//; $str =~ s/\s+$//; return $str; }
sudo rm -rf /
Thanks dargueta, really appreciate it.
I'll test it on Monday.
Panarchy
PS: I didn't change the script at all?
I think you changed it and then uploaded the unchanged version or something, I dunno.
sudo rm -rf /
Nope...
Well anyway, pretty sure this latest script of yours will work, so I'll just give that a go on Monday.
Hi
I've got 300+ .cpp files now, with the correct names. However, when opening the .cpp files, the IP Address didn't go through
I've also got about half that in .exe.manifest & .obj files.
Nothing's been completed compiled.
Please fix the script.
Thanks in advance,
Panarchy
The IP addresses worked fine for me...are you sure you spelled the replacement token right?
sudo rm -rf /
I kept the everything identical to your script.
In fact, I changed my files [CSV & the entire C++ project] to reflect the names you used.
I ran the script from the correct Command-Prompt.
Weird. It worked just fine for me. What I meant was, did you put the token __PUTIPHERE__ everywhere you needed the IP address in your template file, and leave __PUTIPHERE__ alone in the script? You shouldn't need to touch anything in the script except the file names (leave the < before the file name, it means "open for reading"), and the two compile/link commands. (Leave the backticks in, though.)
EDIT: Looking at your compile/link commands, I think you might have to change main.obj to $currhost.obj. I'm not sure, as I don't know how your compiler works.
Last edited by dargueta; 08-05-2009 at 05:09 AM. Reason: Forgot info
sudo rm -rf /
^Hmm... I'll try with that tomorrow.
Thanks
Panarchy
BTW: I'm just using the 90-day trial of Visual Studio 2008 Professional. But there's also the express edition [free], which uses, what I believe to be, the same compiler. Perhaps if we still can't get it to work after this, you could install it?
There are currently 1 users browsing this thread. (0 members and 1 guests)
Bookmarks