我的Python2.7和pypy(使用virtualenv)都在windows 10环境下。从模拟软件中的自述文件中,下面包含了Bash命令中的“for循环”脚本。如何将下面的“for循环”(三行) Bash命令转换为等效的Windows 10 Powershell命令?
“最好并行运行几个进程,例如:
$ for i in {1..10}; do
$ time $pypy epto.py conf_epto/ $i > conf_epto/run-$i.log $
$ done $pypy genStats.py conf_epto 10我试图运行Powershell命令,但遇到了错误:
(my-pypy-env) PS C:\Users\Acer\dev\pypy27home\my-pypy-env\SimpleDA-master> for ( $i = 1; $i -le 10; $i++) {
>> $pypy epto.py conf_epto/ $i > conf_epto/run-$i.log $
>> done}
At line:2 char:7
+ $pypy epto.py conf_epto/ $i > conf_epto/run-$i.log $
+ ~~~~~~~
Unexpected token 'epto.py' in expression or statement.
+ CategoryInfo : ParserError: (:) [], ParentContainsErrorRecordException
+ FullyQualifiedErrorId : UnexpectedToken发布于 2019-04-06 04:54:38
foreach ($i in 1..10) {
Measure-Command { & $pypy epto.py conf_epto/ $i > conf_epto/run-$i.log } | Out-Host
}
& $pypy genStats.py conf_epto 10foreach ($i in 1..10)循环遍历用PowerShell的)创建的数组1..10的元素;复合语句(如foreach )的主体总是以PowerShell中的{ ... }括起来。Measure-Command是PowerShell的等价于Bash的time内置的;它的执行要测量的命令作为脚本块({ ... })传递。- The command inside the script block basically works the same as in Bash, except that in Windows PowerShell `>` creates "Unicode" - UTF16-LE - files by default (in PowerShell _Core_ it is UTF-8 without a BOM). `>` is an effective alias of the [`Out-File`](https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.utility/out-file) cmdlet; to use a different encoding, pipe to it and use the `-Encoding` parameter (e.g., ... | Out-File -Encoding utf8 conf_epto/run-$i.log),但请注意,在PowerShell中,-Encoding utf8总是使用BOM创建UTF-8文件。
- time直接将其结果输出到终端,而不是输出到stdout;Out-Host也是如此;它绕过PowerShell的stdout等价物成功[输出]流。
https://stackoverflow.com/questions/55545335
复制相似问题