#1
  1. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2003
    Location
    Redmond, WA
    Posts
    5
    Rep Power
    0

    Running dos commands from perl (server side script)


    Hi,

    I am a newbie at Perl .. Have looked at this forum and other websites for soln. to my questions, but I havent found any thing useful.

    What i am trying to do is a have a html form (input sent to perl script on server side) and the perl script runs "dos" commands on the server. This is for configuration mangement (building source code).. so I need the directory, file, etc names from the user. In the perl script I have simple dos commands like "cd d:\product" and "mkdir build_folder" , i also run specific software like Visual Source Safe from teh command line.

    I can have the perl script behave like a batch file .. and run the dos commands. THis all works from the 'dos prompt' .. when i run perl script. When I try to use this on teh server, i cant run System() or exec() commands. Nothing happens, no error, etc

    for example: system("dir");
    or exec("dir)"; produces no error or output.

    Is there a way to do this ? I mean can perl be used to run commands / modify the server side file structure .. ?

    Would be great if any one can point me to some helpful hints / resources on programming this ..

    Thanks,
    Keeron
  2. #2
  3. Contributing User
    Devshed Supreme Being (6500+ posts)

    Join Date
    Mar 2003
    Location
    in da kitchen ...
    Posts
    12,871
    Rep Power
    6466
    Code:
    @results=`dir`;
    foreach $result (@results) {
     print "$result";
    }
    HTH
    --Ax
    Last edited by Axweildr; August 25th, 2003 at 03:34 PM.
  4. #3
  5. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2003
    Location
    Redmond, WA
    Posts
    5
    Rep Power
    0
    Originally posted by Axweildr
    [code]
    @results=`dir`;
    foreach $result (@results) {
    print "$result";
    }
    [code]
    HTH
    --Ax
    Thanks axweildr,

    I got by the initial problem by using chdir, mkdir .. (rmdir dosent seem to do any thing, I guess its permissions issue .. )

    Anyways.. now i am back to squre on .. how would I execute programs or batch files from my perl script ? The program or batch files reside on the server. They will modify the server folder contents, execute commands, etc...

    I am trying to create a automated build process (for building products) .. this is a small step - allowing hte user to fill in the details and then launching scripts that just take some arguments ...

    I tried system("../../windows/notepad.exe"),
    system("c:\windows\notepad.exe")
    even system("sample.bat") --- where sample.bat just creates a 1 line text file on the server.

    None of this seems to work. I can make it work when I am on the server and create/run simple perl scripts using command prompt. The problem is when I go to a webbrowser and execute this using webform/perl script

    Thanks
    Keeron

    ps: sorry for the long story Its just that the problem seems to be common, but wasnt answered in detail in this group or other websites I looked at... newbie stuff
  6. #4
  7. Contributing User
    Devshed Supreme Being (6500+ posts)

    Join Date
    Mar 2003
    Location
    in da kitchen ...
    Posts
    12,871
    Rep Power
    6466
    Why not just use Perl the whole way through?

    Tip: Get away from Source Safe (total misnomer IMHO)
    Code:
    $rc=`/path/to/sample.bat`;
    Use backticks to enclose your commands. I assume you're on a windows system

    Code:
    #!/usr/bin/perl
    
    $rc=`sample.bat`;
    print "$rc\n";
    test.pl
    Code:
    dsakjfbjafdjhdsfjbafdjhbdsafjb
    sample.bat
    Code:
    Bad command or file name
    
    C:\My Documents>dsakjfbjafdjhdsfjbafdjhbdsafjb
    Output from above command

    HTH
    --Ax
  8. #5
  9. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2003
    Location
    Redmond, WA
    Posts
    5
    Rep Power
    0
    [QUOTE]Originally posted by Axweildr

    Thanks for the quick reply..

    Here is what I did (following your reply)

    temp.pl ----------

    !D:\Perl\bin\perl.exe

    use CGI;
    $parse = new CGI;
    print $parse->header;

    $rc=`c:\\inetpub\\wwwroot\\t.bat`;

    print "$rc\n";

    ------------------------
    t.bat

    echo hello World > c:\inetpub\wwwroot\hello.txt

    --------

    Now when I run temp.pl file from the browser (using c:\.....\t.pl) it runs pefectly, creating that hello.txt file ...

    When I do the same using http://<servername>/t.pl --> that doesnt work. I dont get any errors, nor any output. The hello.txt is not created. I checked the permissions of c:\inetpub\wwwroot\ and the IIS server has read/write permissions.

    The problem i am facing is when I try to run server-side commands (which modify in some way the files/folder on the server). They work when using c:\...\perlscript.pl ... but not when I run it from the browser using the server address. I also dont know how to track hte error .. (for example, if it was permissions issue, i could change them in specific folders, but here I dont know what it is )

    We are going to CVS soon hence this step towards automation. Since our current build process is in VSS (and use makefiles, batch files, etc to build), we are trying to automate it... and if possible use our existing makefiles/batch files for builds. But this serves as a front end, passing the information to the makefiles/ batch files.

    Appricate your help in this ...

    Thanks,
    keeron
  10. #6
  11. Contributing User
    Devshed Supreme Being (6500+ posts)

    Join Date
    Mar 2003
    Location
    in da kitchen ...
    Posts
    12,871
    Rep Power
    6466
    Keeron,

    hate 2 say it, but it could be because IIS is secure in this respect.

    This works for me on 98SE and Xitami (a lightweight webserver, w/ no security configured on purpose - I use Apache for Testing and production)

    cheers --ax
  12. #7
  13. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2003
    Location
    Redmond, WA
    Posts
    5
    Rep Power
    0
    Originally posted by Axweildr
    Keeron,

    hate 2 say it, but it could be because IIS is secure in this respect.

    This works for me on 98SE and Xitami (a lightweight webserver, w/ no security configured on purpose - I use Apache for Testing and production)

    cheers --ax
    hmm i thought so... since reading up on IIS server (i have IIS 6.0 w/ windows server 2003) i found some issues where IIS was restricted ...

    Well, I'll try to find some work arounds.. if not, I can go ahead with apache server and a linux box.

    Thanks for the help

    - Keeron
  14. #8
  15. Contributing User
    Devshed Supreme Being (6500+ posts)

    Join Date
    Mar 2003
    Location
    in da kitchen ...
    Posts
    12,871
    Rep Power
    6466
    Apache is going to be less forgiving with the output, but here's an idea

    Use RPC to kick off the build, and have the build update a logfile, and to view progress have a page refresh on the logfile every 15/20 seconds

    --Ax
  16. #9
  17. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2003
    Location
    Redmond, WA
    Posts
    5
    Rep Power
    0
    Originally posted by Axweildr
    Apache is going to be less forgiving with the output, but here's an idea

    Use RPC to kick off the build, and have the build update a logfile, and to view progress have a page refresh on the logfile every 15/20 seconds

    --Ax
    Thanks ... Had a ques, how would I use RPC .. ? Any place where I could look more into this ..

    I wanted something where the user fills in the form and the script handles everything. Dont want the user to log in manually into the build machine (since ours is a big company, with lots of differen build machines. We have a CM group, but want to autmoate smaller builds as much as we can .. )

    THanks,
    Keeron

IMN logo majestic logo threadwatch logo seochat tools logo