in reply to How to Get The Session id

What do you mean by "call a Perl Script"? Does it redirect the browser to a Perl "CGI"? Or an ASP using PerlScript? Does it output a HTML form that submits to a Perl "CGI"? Does it use the Shell object to run the Perl script as a process and wait for its completion?

In the last case you'd better get the session id while in the ASP (it's in cookies) and pass it to the script. In the other cases there is another important question. Is the Perl script on the same host as the said ASP? If so you may find the session id in the cookies from the Perl script, if not you will have to get it in the ASP and pass it along.

In either case you should tell us what is it you are trying to acomplish so that we can help.

Jenda
XML sucks. Badly. SOAP on the other hand is the most powerfull vacuum pump ever invented.

Replies are listed 'Best First'.
Re^2: How to Get The Session id
by Nalina (Monk) on Jun 09, 2005 at 04:42 UTC
    Perl script is being clled by the ASP as below.
    <% dim dt,dvnm dim fso,tw dim sdt dim rdt dim pdt dim arg dim wsh dim ses ses=Session.SessionID dvnm = request.form("test") dt = request.form("datebox") if dvnm <> "" and dt <> "" then sdt = split(dt,"/",-1,1) rdt = sdt(2)+"/"+sdt(0)+"/"+sdt(1) pdt = sdt(1)+"."+sdt(0)+"."+sdt(2) response.write(dvnm) response.write(dt) arg = "C:\\AsgReportScripts\\dailyscripts\\dailyreport1.pl "& dvnm ++" "+rdt+" "+ses response.write(arg) set wsh = CreateObject("wscript.shell") wsh.run "cmd.exe /c c:\\perl\\bin\\perl " & arg,1,1 set wsh = nothing response.redirect("filesdisplay.asp?path=C:\reports\"&pdt+"_"+ses) end if %>
    The perl script 'dailyreport1.pl' will open excel file, generate some graph & then close the excel application. The ASP & perl scripts are on the same host. Infact it is running on the remote server. people are accessing ASP pages from their local system & generating the graphs. The scripts will run on the server. Now the problem is when 2 or 3 people try to generate reports simultaneously, the perl script is not closing the excel application properly. Over a period of time there will be many instances of excel running in the task manager of the server.

    So if there is any way to link which instance of excel opened by the perl & findout the PID of it, I can forcefully kill that instance of excel process using killfam.
    I tried to get the process info of all the excel instances running using Win32::Process::Info. But none of the informations is refering to perl. the parent process id of excel will refer to 'svchost.exe' but not perl. Kindly help me out.

      You can modify the Perl script, right? One thing you might try is to modify it so that it doesn't keep starting new Excels, but reuses the already running one. Win32::OLE->GetActiveObject("Excel.Application"); should take care of this. To create the excel object you would use something like this:

      use Win32::OLE; use Win32::Semaphore; $excel = Win32::OLE->GetActiveObject("Excel.Application"); if (!$excel) { print "Not found, locking\n"; my $sem = Win32::Semaphore->new(1, 1, 'ASGdailyreport_StartExcel') +; $sem->wait(); print "locked, looking again\n"; $excel = Win32::OLE->GetActiveObject("Excel.Application"); if (!$excel) { print "still not found, starting\n"; $excel = Win32::OLE->new('Excel.Application') or die "oops\n"; # or # $excel = Win32::OLE->new('Excel.Application','Quit') or die +"oops\n"; # if you wish the Excel to quit once the last script using it +exits } $sem->release(); print "unlocked\n"; } if (!$excel) { die "Could not connect to or start MS Excel!\n"; } print "have an excel $excel\n";
      I'm not sure though whether Excel handles two controling applications correctly, you would have to try that.

      If it doesn't you might try to change the script into a service (see Win32::Daemon or Win32::Daemon::Simple) and control it either via Semaphores and a named pipe or by creating a file containing the parameters in a specific directory. The second might be easier to do from the ASP, you could create the file and redirect to a page that will check whether the report is ready (file appears in the finished reports directory) and either say something like "The report is being generated" and refresh in a few seconds or redirect to the report. Do I make sense?

      Actually you might try if this tiny script doesn't solve the issue. It tries to connect to the running Excels and (if things work right) would close them if there is no other program referencing them. Not sure it would work, but it's worth a try:

      use Win32::OLE; my $i = 0; while (1) { my $excel = Win32::OLE->GetActiveObject("Excel.Application"); last unless $excel; print "Found an excel\n"; last if ++$i > 10; print "Let's see ($i)\n"; }

      Jenda
      XML sucks. Badly. SOAP on the other hand is the most powerfull vacuum pump ever invented.