How to emulate this set or how to assign the result of running system "command" to a variable



Hi all,

I currently have a MS-DOS batch file that am trying to convert to a Perl script.
I have something like this in the .BAT file where variables are "set" based on
some parsing of a variable passed as a command line argument whenever the .BAT
file is executed by the application.

The command line variable is parsed/cut-down-into pieces of source_drive,
source_root, source_file, source_extn and source_path as the contents of the
..BAT file shows below:

========================================================================

rem creates a ftp command file on the root directory of the drive.
set ftp_action=%~dp0%~n1.ftp

rem these aren't used here for debuging purposes
set source_drive=%~dp0
set source_root=%~dp1
set source_file=%~n1
set source_extn=%~x1
set source_path=%~p1

rem get the file path
set destination_path=%~p1

========================================================================

Can someone tell me how can I achieve what the .BAT file is currently trying to
do in a Perl script? I tried doing system "set source_drive=%~dp0"; or
$source_drive=system "set source_drive=%~dp0";to try and assign the output of
the set command to a variable but that does not seem to work? I do not get the
result that am expecting which is the value of %~dp0, instead I presume am
getting more like the return code of running the system "set
source_drive=%~dp0".

Can someone please advise on what am doing wrong and what must I be doing
instead?

I may have to do the same thing for converting UNIX Ksh script to Perl script.
And checking the Ksh script, there is a lot of UNIX commands executed from
within the Ksh script that assigns that output of UNIX commands to variable,
for example, server=`hostname`, I cannot work out how I should be doing this on
Perl, I tried $server=system "hostname" and that does not work as $server when I
try to print it gives 0 (zero) which I think is more like the return code for
running system "hostname" and not the result that am after which is the
hostname of the server.

Thanks in advance.



.



Relevant Pages

  • Re: Problem with one perl script executing another, execution started by Apache httpd
    ... perl script located in a directory tree completely outside the ... directory tree for IndigoPerl, as well as a system command (this is ... The second one just hangs, displaying the initial text, but the script ... What happens if you type this at the command ...
    (comp.lang.perl.misc)
  • Re: Kill processes after web page closes
    ... script and build a new web page based on input. ... If the user clicks the command button and is returned ... find the PERL script is still running. ... I'm not sure if this is exact but possible when user click back button then Appache server send TERM or QUIT signal to your perl proccess. ...
    (comp.lang.perl.misc)
  • Re: Create a context menu entry doing runas
    ... Unfortunately the Perl script is on a networked drive that isn't ... by having the runas command execute a bat file that was local to my ... it doesn't remember drives that I've already mapped. ... the target Perl script must either be on my local drive or I ...
    (microsoft.public.windowsxp.basics)
  • Re: Create a context menu entry doing runas
    ... Unfortunately the Perl script is on a networked drive that isn't ... by having the runas command execute a bat file that was local to my ... it doesn't remember drives that I've already mapped. ... the target Perl script must either be on my local drive or I ...
    (microsoft.public.windowsxp.basics)
  • Re: Scheduled script problem
    ... You can try psexec to run the bat file. ... It can execute the bat remotely, you can run the script on your ... I think I had already tried the Run command, ... So I assume that a separate shell that is being launched to run the strPath ...
    (microsoft.public.windows.server.scripting)