1

バッチファイルで以下のコマンドを使用すると、出力が得られますが、キャリッジリターンとしていくつかのエコーが伴います。

wmic process where Caption='notepad.exe' get ProcessId,WorkingSetSize /Format:Texttable > output.txt

出力:

ProcessId  WorkingSetSize  
4016       6356992         
1548       6189056         

出力でこのキャリッジリターンを取り除く方法は?

EDIT1:

以下で試したリンクされた質問でFoxdriveの有効な回答を参照すると、うまく機能しますが、出力に余分な行が表示されます: ECHO is off. なぜかわからない?

@echo off
setlocal enabledelayedexpansion
(For /F "tokens=1,* delims==" %%A in (' "wmic process where Caption='notepad.exe' get ProcessId,WorkingSetSize /Format:Texttable" ') do (
set "line=%%A %%B"
set "line=!line:~0,-1!"
echo !line!
))>output.txt

output.txt:

ProcessId  WorkingSetSize  
4768       6365184         
5608       5500928         
2888       6037504         
1052       5472256         
ECHO is off.

EDIT2:

ProcessId  WorkingSetSize  
    4768       6365184         
    5608       5500928         
    2888       6037504         
    1052       5472256  

上記の形式でのみ出力し、次を使用してその出力を取得します。

@echo off
setlocal enabledelayedexpansion
(For /F "delims=" %%A in ('"wmic process where Caption='notepad.exe' get  ProcessId,WorkingSetSize /format:Texttable |findstr "[0-9P]" "') do (
set "line=%%A"
echo !line:~0,-1!
)) > output.txt

現在、出力に末尾の CR はありますか? 私のシステムでは hexdump コマンドが機能しません..:(..ご確認いただければ幸いです..:)

4

3 に答える 3

1

これにより、末尾の CR が削除され、スペースで区切られた値が提供されます。

@echo off
setlocal enabledelayedexpansion
(For /F "tokens=2,3 delims=," %%a in ('"wmic process where Caption='notepad.exe' get ProcessId,WorkingSetSize /format:csv |findstr "[0-9]" "') do (
set "num=%%b"
echo %%a !num:~0,-1!
))>output.txt

ファイルの形式は次のとおりです。

624 4923392
9220 4886528

これにより、末尾の CR が削除され、値が CSV 形式で提供されます

@echo off
setlocal enabledelayedexpansion
(For /F "delims=" %%A in ('"wmic process where Caption='notepad.exe' get ProcessId,WorkingSetSize /format:csv |findstr "[0-9]" "') do (
set "line=%%A"
echo !line:~0,-1!
))>output.txt

ファイルの形式は次のとおりです。

PCNAME,956,4960256
PCNAME,4004,4870144
于 2013-10-20T11:35:02.743 に答える
1

これを試して:

wmic process where Caption='notepad.exe' get ProcessId,WorkingSetSize /Format:Texttable|findstr /v "^$">file.txt

出力は (Windows 8) FAR FROM 'HORRIBLE'です:

C:\Users\Private\TEST>wmic process where Caption='notepad.exe' get ProcessId,WorkingSetSize /Format:Texttable|findstr /v "^$">file.txt

C:\Users\Private\TEST>type file.txt
ProcessId WorkingSetSize
8896 8142848

C:\Users\Private\TEST>hexdump -C file.txt
00000000 50 72 6f 63 65 73 73 49 64 20 20 57 6f 72 6b 69 |ProcessId Worki|
00000010 6e 67 53 65 74 53 69 7a 65 20 20 0d 0d 0a 38 38 |ngSetSize ...88|
00000020 39 36 20 20 20 20 20 20 20 38 31 34 32 38 34 38 |96 8142848|
00000030 20 20 20 20 20 20 20 20 20 0d 0d 0a | ...|
0000003c

C:\Users\Private\TEST>for /f "tokens=*" %a in (file.txt) do @echo %a
ProcessId WorkingSetSize
8896 8482816

C:\Users\Private\TEST>(for /f "tokens=*" %a in (file.txt) do @echo %a)|hexdump -C
00000000 50 72 6f 63 65 73 73 49 64 20 20 57 6f 72 6b 69 |ProcessId Worki|
00000010 6e 67 53 65 74 53 69 7a 65 20 20 0d 20 0a 38 38 |ngSetSize . .88|
00000020 39 36 20 20 20 20 20 20 20 38 34 38 32 38 31 36 |96 8482816|
00000030 20 20 20 20 20 20 20 20 20 0d 20 0a | . .|
0000003c

于 2013-10-20T08:19:14.203 に答える
0

あなたのコードを実行する余分な CR や追加のエコーはありません。しかし、あなたはそれらを手に入れているので、エンドロの答えは十分に近い. 不要な行をフィルタリングしようとする代わりに、関心のある行だけを取得してみてください

wmic ..... ^| findstr /B /R "[0-9P]"

数字 (data) または P (ProcessId) で始まる行のみ

于 2013-10-20T11:00:44.307 に答える