2015-04-28 25 views
1

我想使用PowerShell来处理周围的任务,周围运行化学模型的许多迭代,具有稍微不同的输入文件。我的powershell脚本创建一个目录,将模型和输入文件复制到目录中,然后调用模型,它写入一个输出文件。一旦模型完成,脚本会在循环中再次迭代并再次执行所有操作(我已经包含了下面的脚本)。我的问题是,powershell的内存使用率不断上升,直到所有的RAM都被占用。直接调用模型(即只需单击.exe文件)不会产生这样的问题,它只使用很少的内存。 Powershell记住什么不必要的信息,我如何强制它保持记忆清晰?我是Powershell的新手,非常简单的答案,基本上没有假设的先前知识将不胜感激! 感谢您的帮助,PowerShell中的内存使用

#say where the input and the output should be found: 

$source='C:\a_directory_with_input_files' 
$destination='C:\somewhere_for_model_output' 

#unique name for this particular set of runs: 
$suffix='sheath_data_v2_NH3_NO3_AIM' 
$suffix2='AIM_sizes_NH3' 

$names= '17_exp1' , '17_exp2', '18_exp2', '20am_exp1', '20am_exp2' , '20pm_exp1', '20pm_exp2', '20pm_exp3', '21_exp1', '21_exp2', '21_exp3', '05_exp1', '05_exp2', '07_exp1', '07_exp2', '07_exp3' 

#find the bits of name for the directories: 
ForEach ($i in $names) 
{ 

echo $i 
if ($i -eq '17_exp1') {$fn='17_11_2013_15_00-15_41_expa1_NH4'} 
if ($i -eq '17_exp2') {$fn='17_11_2013_16_59-17_49_expa2_NH4'} 
if ($i -eq '18_exp2') {$fn='18_11_2013_04_22-05_30_expa2_NH4'} 
if ($i -eq '20am_exp1') {$fn='20_11_2013_02_26-03_19_expa1_NH4'} 
if ($i -eq '20am_exp2') {$fn='20_11_2013_08_32-09_15_expa2_NH4'} 
if ($i -eq '20pm_exp1') {$fn='20_11_2013_1508-1551_expa1_NH4'} 
if ($i -eq '20pm_exp2') {$fn='20_11_2013_2015-2110_expa2_NH4'} 
if ($i -eq '20pm_exp3') {$fn='20_11_2013_2240-2335_expa3_NH4'} 
if ($i -eq '21_exp1') {$fn='21_11_2013_03_51-04_58_expa1_NH4'} 
if ($i -eq '21_exp2') {$fn='21_11_2013_06_52-07_44_expa2_NH4'} 
if ($i -eq '21_exp3') {$fn='21_11_2013_08_57-09_53_expa3_NH4'} 
if ($i -eq '05_exp1') {$fn='05_12_2013_11_59-12_40_expa1_NH4'} 
if ($i -eq '05_exp2') {$fn='05_12_2013_13_53-14_30_expa2_NH4'} 
if ($i -eq '07_exp1') {$fn='07_12_2013_10_04-10_45_expa1_NH4'} 
if ($i -eq '07_exp2') {$fn='07_12_2013_11_26-12_06_expa2_NH4'} 
if ($i -eq '07_exp3') {$fn='07_12_2013_12_58-13_40_expa3_NH4'} 
if ($i -eq '25_pt1_C9_exp1') {$fn='25_09_2014_19_40-20_15_expa1'} 
if ($i -eq '25_pt1_C9_exp2') {$fn='25_09_2014_21_00-21_31_expa2'} 
if ($i -eq '25_pt1_C9_exp3') {$fn='25_09_2014_22_11-22_41_expa3'} 
if ($i -eq '28_pt1_C9_exp1') {$fn='28_09_2014_16_40-17_06_expa1'} 
if ($i -eq '28_pt1_C9_exp2') {$fn='28_09_2014_17_44-18_10_expa2'} 
if ($i -eq '28_pt1_C9_exp3') {$fn='28_09_2014_18_52-19_15_expa3'} 
if ($i -eq '28_pt1_C9_exp4') {$fn='28_09_2014_19_54-20_20_expa4'} 
if ($i -eq '24_pt2_C9_exp1') {$fn='24_09_2014_16_22-16_50_expa1'} 
if ($i -eq '24_pt2_C9_exp2') {$fn='24_09_2014_17_35-18_00_expa2'} 
if ($i -eq '24_pt2_C9_exp3') {$fn='24_09_2014_18_47-19_15_expa3'} 
if ($i -eq '25_pt2_C9_exp1') {$fn='25_09_2014_23_45-00_10_expa1'} 
if ($i -eq '25_pt2_C9_exp2') {$fn='26_09_2014_01_02-01_30_expa2'} 
if ($i -eq '25_pt2_C9_exp3') {$fn='26_09_2014_02_14-02_40_expa3'} 
if ($i -eq '28_pt2_C9_exp1') {$fn='28_09_2014_20_55-21_20_expa1'} 
if ($i -eq '28_pt2_C9_exp2') {$fn='28_09_2014_22_12-22_41_expa2'} 
if ($i -eq '28_pt2_C9_exp3') {$fn='28_09_2014_23_31-23_55_expa3'} 


#create the new directory, and copy input and model files into it: 
$new_dir=$i+$suffix 
echo $new_dir 

new-item $destination\$new_dir -itemtype directory 

copy-item $source\work\PSI\CLOUD\Windows_modelling\models\chamber_model_$suffix2".exe" $destination\$new_dir\ 

copy-item $source\work\PSI\CLOUD\Windows_modelling\expansion_input_files\input_chamber_$fn.dat $destination\$new_dir\input_chamber.dat 
copy-item $source\work\PSI\CLOUD\Windows_modelling\libraries_and_stuff\* $destination\$new_dir\ 
copy-item $source\work\PSI\CLOUD\Windows_modelling\AIM_input\AMS_frac_$fn$suffix.dat $destination\$new_dir\AMS_frac.dat 
copy-item $source\work\PSI\CLOUD\Windows_modelling\AIM_input\dist_$fn$suffix.dat $destination\$new_dir\dist.dat 
copy-item $source\work\PSI\CLOUD\Windows_modelling\AIM_input\traj_$fn$suffix.dat $destination\$new_dir\traj.dat 
copy-item $source\work\PSI\CLOUD\Windows_modelling\AIM_input\*$fn$suffix.dat $destination\$new_dir\ 

#now go there: 
cd $destination\$new_dir 
# and call the model, dumping any of the stuff the model outputs to the screen: 
$(
./chamber_model_AIM_sizes_NH3.exe 
) | Out-Null 

} 

回答

2

当您使用命令$(blah.exe) | out-null这将导致PowerShell来保留所有blah.exe的输出在内存中。我在我的系统上测试一个行脚本:

cmd /c "dir c:\*.* /s" | out-null

PowerShell的内存使用量不会攀升。但随着:

$(cmd /c "dir c:\*.* /s") | out-null

Powershell的记忆立即开始登山和一路攀升。

+0

@Frog如果解决了问题,请将其标记为答案。谢谢! –

+0

非常好,这非常有帮助。这完美地解决了这个问题。 – Frog

相关问题