automatization with powershell Start-Process

64 views
Skip to first unread message

Erhy

unread,
Jan 17, 2020, 5:01:09 PM1/17/20
to vim_use
Hallo!
 My task is, to convert many files encoding in latin1 to UTF-8

I know the sequence which works:

open a file
set set fileencoding=utf-8
set bomb
wrtite to another file

but there are problems with the argument list
this fails:
Start-Process -FilePath 'C:/Program Files (x86)/Vim/vim82/vim.exe' -wait -ArgumentList ('"S:\testConcToUTF2\b Ansi copied.txt"', '-c set fileencoding=utf-8')


please give me an advice
Erhy

skeept

unread,
Jan 17, 2020, 5:18:21 PM1/17/20
to vim_use
I think the only think you need to change is the last part:

'-c set fileenconding=utf-8' should be changed to

'-c', '"set fileencoding=utf-8"'
Message has been deleted

Erhy

unread,
Jan 18, 2020, 6:34:35 AM1/18/20
to vim_use
Thank you it worked

Here an example of the full command to convert encoding to UTF-8 with BOM

Start-Process -FilePath 'C:/Program Files (x86)/Vim/vim82/vim.exe' -wait -ArgumentList ('"S:\testConcToUTF2\b Ansi copied.txt"', '-c', '"set fileencoding=utf-8"', '-c', '"set bomb"', '-c', '"w S:/testConcToUTF2/b Ansi copied now UTF.txt"', '-c', '"q!"' )

Erhy

unread,
Jan 25, 2020, 9:02:27 AM1/25/20
to vim_use
and now a better Start-Process which don't flicker:

    $argRead = '"e ' + $filename + '"'
    $argwrite
= '"w! ' + $tmpFilepath + '"'
   
Start-Process -FilePath $vimPath -wait -WindowStyle Hidden -ArgumentList ( `
        '-c', '"set noswapfile"', '-c', $argRead, `

       
'-c', '"set fileencoding=utf-8"', '-c', '"set bomb"',
`
        '-c', $argwrite, '-c', '"q!"' )



Reply all
Reply to author
Forward
0 new messages