Uso del Write-Host cmdlet como la última declaración de tu canalización La salida de PowerShell sin adornos normales parece observar las dimensiones de la ventana de la consola principal, y recorta/ajusta las líneas de salida al ancho-1. El cmdlet Write-Host omite este paso y escribe directamente en stdout sin ningún otro munging.
He aquí un ejemplo, que lee un archivo JSON, y escribe Javascript de salida que se suma el JSON para una cadena grande (comentarios para esterilizar):
powershell -Command "$input | ForEach-Object { \"manifestBlob += \"\"\" + ($_ -replace \"\"\"\", \"\\\"\"\") + \"\n\"\";\" } | Write-Host" <manifest.json> buildmanifest.js
Aquí es un archivo de entrada de ejemplo:
// 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",
}
Y la salida al utilizar 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";
Y, por último, un ejemplo de la ter Rible cosas que suceden si dejar de lado el cmdlet Write-Host (suponiendo una anchura de consola de 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";
'fuera File' tiene un parámetro' -Width', también. Su documentación indica que todo lo que está más allá del ancho está truncado (no envuelto). Así que supongo que esto se trunca primero en 4096 caracteres (lo que es un número extrañamente no redondo) y luego en el ancho de la ventana de la consola. Si bien no se ajusta, trunca las líneas más largas que pueden no ser intencionales. – Joey
4096 no es impar y no es redondo. Es 2^12 –