PowerShell中的内存使用情况

时间:2015-04-28 13:08:19

标签: powershell memory

我正在尝试使用Powershell来处理围绕运行化学模型的许多次迭代的平凡任务,输入文件略有不同。我的powershell脚本创建了一个目录,将模型和输入文件复制到目录中,并调用模型,该模型编写单个输出文件。模型完成后,脚本会再次循环遍历循环并再次执行所有操作(我已在下面添加了脚本)。我的问题是PowerShell的内存使用量不断增加,直到所有RAM都被占用。直接调用模型(即只是单击.exe文件)不会产生这样的问题,它只占用很少的内存。什么不必要的信息是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

}

1 个答案:

答案 0 :(得分:2)

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

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

Powershell内存使用量没有攀升。但是:

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

Powershell记忆立即开始攀爬并继续攀爬。