Используйте командлет Write-Host в качестве последнего оператора вашего конвейера. Обычный вывод без надписей PowerShell, похоже, просматривает размеры окна родительской консоли и обрезает / оборачивает выходные строки в width-1. Командлет Write-Host обходит этот шаг и выполняет прямую запись в стандартный вывод без каких-либо дополнительных действий.
Вот пример, который читает файл JSON и записывает вывод javascript, который добавляет JSON в большую строку (с сохранением комментариев):
powershell -Command "$input | ForEach-Object { \"manifestBlob += \"\"\" + ($_ -replace \"\"\"\", \"\\\"\"\") + \"\n\"\";\" } | Write-Host" < manifest.json > buildmanifest.js
Вот пример входного файла:
// File: manifest.json
//
// Description:
// manifest for chrome plug-in
{
"manifest_version": 2,
"version": "0.0.0",
// the ID is: sdfjkghsdfjkghjksdfghjkfhjkdfjff
"key": "sdfjkhsdfjkghjksdfghkjsdhgsdjkgfhjklsdfhgjklsdfhgjklsdhfgkljsdfhgkljsdhklgjsdhfjklghsdfjklghsdjklfghjksdfhgjksdhfgjklhsdfjkl",
"content_scripts": [ { "matches": ["http://*/*", "https://*/*"], "js": ["content.js"], "run_at": "document_start" } ],
// this is the standard LOCAL install location - but if this extension is published to the app-store, this value gets overridden (that is okay and even good)
"update_url": "file:///C:/Program%20Files/MyProduct/Update.xml",
}
А вывод при использовании Write-Host:
manifestBlob += "\n";
manifestBlob += "// File: manifest.json\n";
manifestBlob += "//\n";
manifestBlob += "// Description:\n";
manifestBlob += "// manifest for chrome plug-in\n";
manifestBlob += "\n";
manifestBlob += "{\n";
manifestBlob += " \"manifest_version\": 2,\n";
manifestBlob += "\n";
manifestBlob += " \"version\": \"0.0.0\",\n";
manifestBlob += "\n";
manifestBlob += " // the ID is: sdfjkghsdfjkghjksdfghjkfhjkdfjff\n";
manifestBlob += " \"key\": \"sdfjkhsdfjkghjksdfghkjsdhgsdjkgfhjklsdfhgjklsdfhgjklsdhfgkljsdfhgkljsdhklgjsdhfjklghsdfjklghsdjklfghjksdfhgjksdhfgjklhsdfjkl\",\n";
manifestBlob += "\n";
manifestBlob += " \"content_scripts\": [ { \"matches\": [\"http://*/*\", \"https://*/*\"], \"js\": [\"content.js\"], \"run_at\": \"document_start\" } ],\n";
manifestBlob += "\n";
manifestBlob += " // this is the standard LOCAL install location - but if this extension is published to the app-store, this value gets overridden (that is okay and even good)\n";
manifestBlob += " \"update_url\": \"file:///C:/Program%20Files/MyProduct/Update.xml\",\n";
manifestBlob += "}\n";
И, наконец, пример ужасных вещей, которые происходят, если вы пропустите командлет Write-Host (при условии, что ширина консоли равна 60):
manifestBlob += "\n";
manifestBlob += "// File: manifest.json\n";
manifestBlob += "//\n";
manifestBlob += "// Description:\n";
manifestBlob += "// manifest for chrome plug-in\n";
manifestBlob += "\n";
manifestBlob += "{\n";
manifestBlob += " \"manifest_version\": 2,\n";
manifestBlob += "\n";
manifestBlob += " \"version\": \"0.0.0\",\n";
manifestBlob += "\n";
manifestBlob += " // the ID is: sdfjkghsdfjkghjksdfghjkf
hjkdfjff\n";
manifestBlob += " \"key\": \"sdfjkhsdfjkghjksdfghkjsdhgs
djkgfhjklsdfhgjklsdfhgjklsdhfgkljsdfhgkljsdhklgjsdhfjklghsd
fjklghsdjklfghjksdfhgjksdhfgjklhsdfjkl\",\n";
manifestBlob += "\n";
manifestBlob += " \"content_scripts\": [ { \"matches\":
[\"http://*/*\", \"https://*/*\"], \"js\": [\"content.js\"]
, \"run_at\": \"document_start\" } ],\n";
manifestBlob += "\n";
manifestBlob += " // this is the standard LOCAL install
location - but if this extension is published to the app-st
ore, this value gets overridden (that is okay and even good
)\n";
manifestBlob += " \"update_url\": \"file:///C:/Program%2
0Files/MyProduct/Update.xml\",\n";
manifestBlob += "}\n";