3
5

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

Start-Processとログファイル

Posted at

Start-Processコマンドを実行し、外部プログラムを呼び出すことはよくあることだと思います。
ただ、その結果をファイルに出力しようとしてはまりました。。。

今後の覚書として。。

Start-Processの基本構文

基本構文
Start-Process -FilePath プログラム -ArgumentList オプション -RedirectStandardOutput ログファイル

例:jstatを実行し、結果をgc.logファイルに出力する

例:jstatを実行し、結果をgc.logファイルに出力する
Start-Process -FilePath "c:\jdk-11.0.2\bin\jstat.exe" -ArgumentList "-gc 8855 5000" -RedirectStandardOutput c:\gc.log

※この時、ログファイルは上書きされてしまうということに注意。
 事前に実行時刻をログファイルへ出力していても上書きされるため消える。
 代替案として実行時刻を変数に格納し、その後ファイル名に付与することとした。

ファイル名に実行時刻を付与する
$DateTime=Get-Date (Get-Date).Datetime  -Format yyyyMMdd_HHmmss
rename-item -Path "c:\gc.log" -NewName "c:\gc_$DateTime.log"
3
5
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
3
5

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?