batch file - Running commands over Plink from PowerShell fails with "■e: not found" -
thanks help. have problem script. trying convert script batch powershell, try learn new powershell know other languages decent @ programming. script creates kivacommands.txt
file used in plink executed on server. batch script works fine plink when converted powershell plink line errors on -m
switch.
sh: ■e: not found
i error no matter commands in txt file, if file empty. plink line works fine if pass single command execute. code i'm having trouble with.
$hostlogin = "myserver" $passwd = "mypassword" $command = "h:\kivacommands.txt" c: cd \ cd "program files (x86)\putty" ./plink.exe -ssh $hostlogin -p 22 -pw $passwd -m $command
the cd
commands way work. tried other ways of giving whole path , creating variable path plink not execute.
so after more troubleshooting, have narrowed down file created. if manually create file works fine script creates file before calling plink. have tried 3 different ways create file
"exit ^| sqlplus / @kiva_extract $assessoryear" | set-content h:\kivacommands.txt -encoding unicode "exit ^| sqlplus / @kiva_extract $assessoryear" | out-file h:\kivacommands.txt -encoding unicode "exit ^| sqlplus / @kiva_extract $assessoryear" > h:\kivacommands.txt
the file creates fine , looks right plink cannot open correctly.
the utf-8 output file generated powershell starts utf-8 bom mark.
unix system typically not expect bom, remote shell tries interpret command, failing. bom square character (■
) in error message:
sh: ■e: not found
i not know how prevent bom appearing in output.
but can strip ex-post:
$mypath = "h:\kivacommands.txt" $myfile = get-content $mypath $utf8nobomencoding = new-object system.text.utf8encoding($false) [system.io.file]::writealllines($mypath, $myfile, $utf8nobomencoding)
Comments
Post a Comment