×
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!
  • Students Click Here

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

need to execute batch file inside perl script after replacing string

need to execute batch file inside perl script after replacing string

need to execute batch file inside perl script after replacing string

(OP)
I am new to perl

I need to call batch file inside perl script

I know how to call using system function

but the thing is i need to replace some characters in batch file before calling it.

please advise
 

RE: need to execute batch file inside perl script after replacing string

(OP)

my $cod="c:\\Program\\ Files";


system("start $cod");

when i am doing this it throws error
the error indicates its not accepting space between program and files
but my path is c:\program files, there is space between program and files
tried lot of ways
finally popsting here
please help

RE: need to execute batch file inside perl script after replacing string

Your second question answered here.  Please don't multi-post.

For your first question, can you give an example of what you have before and what you want to replace it with?

Basically you need to read in the batch file, replace the strings using s/before/after/ type operators, and write the batch file again.

Annihilannic
tgmlify - code syntax highlighting for your tek-tips posts

RE: need to execute batch file inside perl script after replacing string

(OP)
Thank you very much

you saved my time.

RE: need to execute batch file inside perl script after replacing string

(OP)
my goal is to execute this .cmd file inside perl script

this is my .cmd file :

"D:\Program Files\Tivoli\TSM\TDPSql\tdpsqlc" backup master FULL /sqlbuff=2 /strip=2 /SQLSERV=test >> D:\logs\test.OUT 2>&1

this is my perl code:

#!/usr/bin/perl

use warnings;
use strict;
use Getopt::Long;
use Win32::SqlServer qw(SCALAR);

GetOptions( 'd=s' => \my $database,
            'i=s' => \my $servername,
);

# Log in to server .

my $sqlsrv = Win32::SqlServer::sql_init($servername, $database, 'gentle', 'Northwind');
# Our SQL statement.

my $stmnt = <<SQLEND;
BACKUP database "$database" TO DISK = N'c:\\bak\\master.dmp'
SQLEND

# Run query.
my $result = $sqlsrv->sql($stmnt, SCALAR);

# Print results.
foreach my $name (@$result) {
    print "$name\n";
}
now i am calling .cmd file in perl script like this:

my $cod=""D:\Program Files\Tivoli\TSM\TDPSql\tdpsqlc" backup master FULL /sqlbuff=2 /strip=2 /SQLSERV=test >> D:\logs\test.OUT 2>&1";
system("start \"Title\" \"$cod\"");;

now the thing is i need to replace master to $database and test to $servername

I will update you if i had questions in this situation

Thanks for your response.

 

RE: need to execute batch file inside perl script after replacing string

Try this:

CODE

my $cod="\"D:\\Program Files\\Tivoli\\TSM\\TDPSql\\tdpsqlc\" backup $database FULL /sqlbuff=2 /strip=2 /SQLSERV=$servername >> D:\\logs\\test.OUT 2>&1";
system("start \"Title\" $cod");

Annihilannic
tgmlify - code syntax highlighting for your tek-tips posts

RE: need to execute batch file inside perl script after replacing string

(OP)
Sure will try and update you

Thanks

RE: need to execute batch file inside perl script after replacing string

(OP)
ran well
can you please suggest about this.

GetOptions( 'd=s' => \my $database,
            'i=s' => \my $servername,
             'TYPE=s' => \my $type,
              'LOCATION=s' => \my $loc,

If  im not entering any values while executing this perl code,
 how can i set any default valuyes to above parameters.

now im executing like this: perl filename.pl -i name -d name1
-type name2 -location name3

but if i want to execute like perl filename.pl, it should execute with some default values for i,d,type and location.

PLease suggest, tried lot ways

 

RE: need to execute batch file inside perl script after replacing string

(OP)
got it by passing default values to parameters inside perl script

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members! Already a Member? Login

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close