Click to See Complete Forum and Search --> : ActiveXObjects and Perl


subesc
12-07-2005, 11:47 AM
(x-posted in Javascript)

I'm trying to write a page that will allow any user to choose a directory that exists on their machine to submit through a certain form. Currently, I am doing this by using an ActiveXObject in a javascript function and calling a Perl Script that reads every directory within the one it was sent. My workaround is that I am writing this output from the Perl Script to a text file, then reading it using JavaScript.

My question is: Is there another way to communicate the output from my Perl Script to my javascript function that uses an activeXObject? Right now, the perl script is not writing to the text file quick enough, so the function is actually reading data from the last pass, not the current one.

Here is my code that I currently am using.



function viewSub() {
document.form1.hiddenValue.value = document.form1.Dir.value;
confirm ( document.form1.hiddenValue.value );

var getSub = new ActiveXObject( "WScript.shell" );
getSub.run('subdir.pl -f '+document.form1.Dir.value);
// Calls Perl Script with the value of a field, which writes to a text file.

var fso, f, r;
fso = new ActiveXObject("Scripting.FileSystemObject");
f = fso.OpenTextFile("C:\\subdir.txt", 1);
r = f.ReadLine();
r = r.substring(0, r.length-1);
var subdirs = r.split(",");
for (var i=0;i<subdirs.length;i++) {
subdirs[i] = subdirs[i].concat("\\");
var addText = subdirs[i];
var addValue = subdirs[i];

document.form1['chooseDirectory'].options[i]=new Option(addText,addValue);
}
f.Close();
}


I would prefer to not have to use a text file in the first place, since it seems like it could be fairly faulty.

I attempted to use the Exec function for an ActiveXObject as shown:



function viewSub() {
document.form1.hiddenValue.value = document.form1.Dir.value;
confirm ( document.form1.hiddenValue.value );

var shell = new ActiveXObject( "WScript.shell" );
var exec = shell.Exec('subdir.pl -f '+document.form1.Dir.value);
// Calls the Perl Script which, in this case, would print the results instead of write them to a text file.

var output = shell.StdOut.Write(exec.StdOut.ReadAll());
document.write ( output ); // For testing purposes.
}


This script returns an error saying that my subdir.pl file is not a "valid Win32 object".

Any input on this issue would be greatly appreciated. It is making me nuts!