如何将几行批处理脚本转换为perl脚本

时间:2014-03-27 11:39:25

标签: sql perl batch-file

我是perl脚本的新手。您能否建议我如何将几行批处理脚本转换为perl脚本。

我的批处理脚本是:

:: delete *.bak file from store_id Patel General

del "D:\Database\Patel General Store\*.bak"

:: change Directory 

cd "C:\Program Files\7-Zip"

:: extract new data from drop box to database folder

"C:\Program Files\7-Zip"\7z.exe  -o"D:\Database\Patel General Store\" e "D:\Dropbox\Database Backup\Patel General Store\*"
d

:: Rename new .bak data with storelocation_storeid_store_na

cd\

rename "D:\Database\Patel General Store\*.bak" MUM_099_Patel_General_Stores_30.bak

cd\


sqlcmd -S"ADMIN-PC\SQLEXPRESS" -E -Q "restore database MUM_099_Patel_General_Stores_30 from disk='D:\Database\Patel General Store\MUM_099_Patel_General_Stores_30.bak' with move 'Account180001' to 'C:\Program Files\Microsoft SQL Server\MSSQL.1\MSSQL\Data\MUM_099_Patel_General_Stores_30.mdf',Move 'Account180001_LOG' to 'C:\Program Files\Microsoft SQL Server\MSSQL.1\MSSQL\Data\MUM_099_Patel_General_Stores_30_Log.ldf',replace"

如果新商店添加,那么我需要复制所有行并粘贴一次。它都是硬编码的,请提出一些建议,以便我免除这种硬编码

1 个答案:

答案 0 :(得分:1)

使用来自perl的system()来电。

即将上述命令放在批处理文件中,例如xyz.bat 并从perl使用

system("xyz.bat"); presuming xyz.bat位于您的perl目录中。执行命令后,控件将返回到perl脚本。

如果您不想返回调用perl脚本...请使用' exec'而是如下..

exec("xyz.bat");

快乐的计算............

相关问题