我想使用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
}
@Frog如果解決了問題,請將其標記爲答案。謝謝! –
非常好,這非常有幫助。這完美地解決了這個問題。 – Frog