shreko has asked for the wisdom of the Perl Monks concerning the following question:

I am working on automation of a business process that looks like this. Through the web interface (php) user enters few parameters about product, and then I need to generate few files in different format. This is metal fabrication business and plasma cutting machine needs .dxf file. I have installed CAD program that I want to feed with AutoCAD (.scr) script generated during the web phase. This works from the command line: `s:\bcad\icad.exe /b s:\scripts\my.scr` which tells the OS to execute icad.exe and start executing my.scr. In my.scr there are instructions for drawing the shape, exporting to .dxf, saving to native format .dwg, printing to .pdf and finally exiting/closing icad.exe. Then I need to move these files to a different locations. I was thinking to make it as a perl script which will scan the directory where web script drops the my.scr constantly or every few minutes and execute above command, then finally delete the my.scr. My web script is in php and I tried exec(), but process starts in the background, sitting there and my web page hangs. I would appreciate if someone can show me few lines of code or point me to an existing similar solution to this problem Thanks, Shreko

Replies are listed 'Best First'.
Re: Windows scripting
by davidrw (Prior) on Jul 05, 2005 at 19:13 UTC
Re: Windows scripting
by Jenda (Abbot) on Jul 05, 2005 at 20:27 UTC

    You said it yourself, you want a script that will monitor the directory so you can't start it from the PHP. Besides you will likely want to run this script and then the icad using a different account than the one the PHP scripts run under.

    Create a service (Win32::Daemon or Win32::Daemon::Simple or PDK's PerlSvc) that will either monitor the directory via Win32::ChangeNotify or scan it for changes every now and then and then call the icad and move the files.

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

Re: Windows scripting
by Nkuvu (Priest) on Jul 05, 2005 at 19:17 UTC
    From the very first line of perldoc -f exec

    The "exec" function executes a system command and never returns -- use "system" instead of "exec" if you want it to return.

    This would be something like system "some_system_command"; If you need to capture the output from the system command, use backticks: my @output = `system_command`;

    You may also want to read about qx which can be found in perldoc perlop.

    Edit: The first time I read this, I could have sworn you said your web script was in Perl and you were using exec(). So my note about perldoc -f exec isn't as applicable as I thought, given that your script is actually in PHP. But it's not bad advice, really, just not quite on the mark. *sigh* That's what I get for posting while trying to eat lunch.