我正在尝试为我的儿子创建通过 DOSBox 启动特定游戏的快捷方式,并且我尝试通过使用以下脚本动态更改 DOSBox “.conf”文件的“[autoexec]”部分来实现这一点:
((Get-Content -path C:\Users\skewb\AppData\Local\DOSBox\dosbox-0.74-3.conf -Raw) -replace "\[autoexec\]*", "`[autoexec`]`nMOUNT C`r`nE:\Games\DOSGames`r`nC:`r`ncd SSGG`r`nssg`r`n") | Set-Content -Path C:\Users\skewb\AppData\Local\DOSBox\dosbox-0.74-3.conf
start-process "D:\Program Files (x86)\DOSBox-0.74-3\DOSBox.exe"
我几乎已经让它工作了,但是现在每次我运行脚本时,它都会附加到自动执行部分的末尾(嗯......从技术上讲是该部分的开头,但无论如何)像这样:
原来的:
[autoexec]
# Lines in this section will be run at startup.
# You can put your MOUNT lines here.
预期输出:
[autoexec]
MOUNT C
E:\Games\DOSGames
C:
cd SSGG
ssg
实际产量:
[autoexec]
MOUNT C
E:\Games\DOSGames
C:
cd SSGG
ssg
MOUNT C
E:\Games\DOSGames
C:
cd SSGG
ssg
MOUNT C
E:\Games\DOSGames
C:
cd SSGG
ssg
MOUNT C
E:\Games\DOSGames
C:
cd SSGG
ssg
MOUNT C
E:\Games\DOSGames
C:
cd SSGG
ssg
# Lines in this section will be run at startup.
# You can put your MOUNT lines here.
它似乎[autoexec]
正确地识别了该部分,但随后在换行符处停止了,我猜?我也尝试过像这样在“查找”中识别换行符(当然无济于事):
((Get-Content -path C:\Users\skewb\AppData\Local\DOSBox\dosbox-0.74-3.conf -Raw) -replace "\[autoexec\](`r`n)(*)", "`[autoexec`]`nMOUNT C`r`nE:\Games\DOSGames`r`nC:`r`ncd SSGG`r`nssg`r`n") | Set-Content -Path C:\Users\skewb\AppData\Local\DOSBox\dosbox-0.74-3.conf