2014-03-27 131 views
0

我是perl脚本中的新成员。你能建议我如何将几行批处理脚本转换为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" 

如果新的商店,向其中加入我需要复制所有的线路和粘贴一次。这是全部硬编码,请请建议一些事情,这样我就可以免除这个硬编码

+0

你当然已经尝试过任何东西。你为什么不张贴这个,以便我们可以用它作为一个起点? –

回答

1

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

即把上面的命令在批处理文件中说xyz.bat 和perl的使用

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

如果你不想返回到调用perl脚本...使用 'EXEC',而不是如下..

exec("xyz.bat");

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

+0

谢谢你的答复。但我想删除批处理脚本中的硬代码行,因为这些行重复了很多次。 – Rups