Jump to content

how to open an command file (.cmd)

- - - - -

This topic has been archived. This means that you cannot reply to this topic.
5 replies to this topic

#1
summer5

summer5

    Newbie

  • Members
  • Pip
  • 4 posts
Hi everyone,

I'm trying to open an command file in windows, but fail. I had try save the command line in .txt and open it using perl but fail too.

Can somebody please help me, point me a direction?

Thanks,
Summer

#2
ferovac

ferovac

    Learning Programmer

  • Members
  • PipPipPip
  • 84 posts
not sure what you mean perl is in .pl file and you need to download a interpreter to run it

#3
summer5

summer5

    Newbie

  • Members
  • Pip
  • 4 posts
i want to write a perl script(.pl) to execute a command file(.cmd) after i replace the value in .cmd file.
To make perl script perform these function, i need an intepreter is it?

#4
summer5

summer5

    Newbie

  • Members
  • Pip
  • 4 posts
yes,i do install the perl interpretor: Activeperl. :>

#5
Alexander

Alexander

    It's Science!

  • Moderators
  • 4,124 posts
I'm not sure what you mean, but are you meaning you wish to open a process (on the .cmd file) after modifying it, and run it?
Be sure to read the updated FAQ! || Health is achieved through the same 10,000 steps.
If a suggested code/method fails, informing us is less important than telling us why or what errors occurred.

#6
dargueta

dargueta

    Writes binary right handed and hex left handed

  • Moderators
  • 4,722 posts
I think I got it. The OP wants to use a Perl script to modify a batch program (.cmd extension) and then run that batch program.

#!/usr/bin/env perl

use strict;
use warnings;
use POSIX;

my ($fd, $filetext, $endl);

open($fd, "+<", $ARGV[0]) or die "Failed to open file for r/w: $!\n";

$endl = $/;
undef $/;
$filetext = <$fd>;
$/ = $endl;

$filetext =~ s/<thing to replace>/<stuff to replace with>/g;
seek($fd, 0, SEEK_SET);
print $fd $filetext;
close($fd);

system($ARGV[0]<other args here>);

# more stuff if necessary here

exit(1);
Can't test it right now, but it should work. Note that this assumes that the first argument passed to the script is the name of the file you want to modify and run. Replace everything in < > as necessary, except <$fd>.
sudo rm -rf /