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

Hi Ppl, I'm new to Perl. I have written a code in C# for the below funtion:

1. open cmd 2. Set the directory in which the program is running as the currect path 3. Detect a file with extension ".mobi" or ".prc" or ".epub" and run certain actions for certain filetypes: 1. for MOBI: "kindletool.exe strip_source filename.mobi " 2. for PRC: "kindletool.exe strip_source filename.prc" 3. If there is a file with ".epub" extension then rename the extension to ".zip".

can someone please help me with this

  • Comment on Automating cmd prompt command execution

Replies are listed 'Best First'.
Re: Automating cmd prompt command execution
by choroba (Cardinal) on Sep 08, 2015 at 09:38 UTC
    I don't understand what you mean by 1. and 2. The current directory is the one in which the program is running, unless you change it. The rest can be implemented by checking the extension:
    #!/usr/bin/perl use warnings; use strict; for my $file (glob '*.mobi *.prc *.epub') { my ($ext) = $file =~ /\.(.*)/; if ($ext =~ /mobi|prc/i) { my $status = system qw{ kindletool.exe strip_source }, $file; warn "Failure $status: $file" if $status; } elsif (lc $ext eq 'epub') { (my $newname = $file) =~ s/\.epub$/.zip/; rename $file, $newname or warn "Failure $!: $file"; } }

    For details, see glob, system, lc, rename.

    لսႽ† ᥲᥒ⚪⟊Ⴙᘓᖇ Ꮅᘓᖇ⎱ Ⴙᥲ𝇋ƙᘓᖇ

      thanks a lot for the help. What I meant was, the kindletool.exe tool will be kept in a particular path. Ex : C:\Users\user\Desktop\Convert. So this code which is given, will run from bin folder of perl. I want to run it on the above mentioned path.

        Ignore my reply !! I figured it out...i was bit confused :) now its clear..one more help, when the code is done running, I should get a message saying " Do u want to continue? Press Y to run the program again or press N to exit"

Re: Automating cmd prompt command execution
by Corion (Patriarch) on Sep 08, 2015 at 09:32 UTC

      I dont know perl..that's where the problem is :P ..I'm trying to lean it ..but i have a bit of time constrain to finish it..

      The code which u gave works perfectly fine.. I just need the below message to display: "Do you want to continue? Press Y to continue and N to exit"

        We're here to help you learn; not to do it for you.

        With that in mind, try to learn by reading Getting user input and answers. You might want to find other nodes related to your question by using Super Search or your favorite search engine with terms like "prompt user" (among many other possibilities).