Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

need to execute batch file inside perl script after replacing string

Status
Not open for further replies.

mohankrishna919

Programmer
Jan 18, 2012
14
US
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
 

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
 
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
[small]tgmlify - code syntax highlighting for your tek-tips posts[/small]
 
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.

 
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
[small]tgmlify - code syntax highlighting for your tek-tips posts[/small]
 
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

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top