{"id":2232,"date":"2012-06-15T15:05:53","date_gmt":"2012-06-15T13:05:53","guid":{"rendered":"http:\/\/blog.unelink.es\/?p=2232"},"modified":"2012-06-12T16:13:56","modified_gmt":"2012-06-12T14:13:56","slug":"uso-de-las-redirecciones-de-error-en-bash","status":"publish","type":"post","link":"https:\/\/hosting.airetech.es\/blog\/wiki\/uso-de-las-redirecciones-de-error-en-bash\/","title":{"rendered":"Uso de las redirecciones de error en Bash"},"content":{"rendered":"<p><strong>M\u00e9todo 1. (Redirecci\u00f3n de errores)<\/strong><\/p>\n<pre>comando 2&gt; error.log<\/pre>\n<p>Este primer m\u00e9todo SIEMPRE crea el fichero <em>error.log<\/em>, pero solo tendr\u00e1 contenido si la ejecuci\u00f3n del comando fallase por cualquier motivo.<\/p>\n<p>La salida por consola es suprimida y para ver el motivo del fallo deber\u00edamos inspeccionar el fichero <em>error.log<\/em>.<\/p>\n<p>&nbsp;<\/p>\n<p><strong>M\u00e9todo 2. (Redirecci\u00f3n de la salida - error y est\u00e1ndar)<\/strong><\/p>\n<pre>comando &amp;&gt; comando.log<\/pre>\n<p>Este segundo m\u00e9todo SIEMPRE crea el fichero comando.log y SIEMPRE tiene contenido.<\/p>\n<p>La salida, tanto de \u00e9xito como de error, es redirigida al fichero <em>comando.log<\/em>.<\/p>\n<p>&nbsp;<\/p>\n<p><strong>M\u00e9todo 3. (Redirecci\u00f3n est\u00e1ndar hacia fichero y supresi\u00f3n del error por la salida est\u00e1ndar)<\/strong><\/p>\n<pre>comando &gt; comando.log 2&gt;&amp;1<\/pre>\n<p>Este segundo m\u00e9todo SIEMPRE crea el fichero <em>comando.log<\/em> y tendr\u00e1 contenido solo si el comando tiene \u00e9xito y produce alg\u00fan tipo de salida.<\/p>\n<p>Otro modo de redireccionar la salida exitosa de un comando, pero esta vez a un pipe:<\/p>\n<pre>ls \/bin\/ 2&gt;&amp;1 | more<\/pre>\n<p>&nbsp;<\/p>\n<p><strong>M\u00e9todo 4. (Redireccionar la salida est\u00e1ndar hacia la salida de error stdout to stderr)<\/strong><\/p>\n<pre>comando 2&gt;&amp;1<\/pre>\n<p>&nbsp;<\/p>\n<p><strong>M\u00e9todo 5. (Redireccionar la salida est\u00e1ndar hacia un fichero y la de error hacia otro)<\/strong><\/p>\n<pre>(ls &gt; comando.log) &gt;&amp; error.log<\/pre>\n<p>Este m\u00e9todo SIEMPRE crear\u00e1 ambos ficheros, pero solo 1 de ellos tendr\u00e1 contenido, dependiendo de si la salida del comando ejecutado fue exitosa o no.<\/p>\n<p>A modo de consulta, aqu\u00ed os dejo una lista de los c\u00f3digos y su salida:<\/p>\n<pre>0 stdin (teclado)\r\n1 stdout (salida est\u00e1ndar, como el monitor)\r\n2 stderr (salida est\u00e1ndar de error, tambi\u00e9n el monitor)<\/pre>\n","protected":false},"excerpt":{"rendered":"M\u00e9todo 1. (Redirecci\u00f3n de errores) comando 2&gt; error.log Este primer m\u00e9todo SIEMPRE crea el fichero error.log, pero solo tendr\u00e1 contenido si la ejecuci\u00f3n del comando fallase por cualquier motivo. La salida por consola es suprimida y para ver el motivo del fallo deber\u00edamos inspeccionar el fichero error.log. &nbsp; M\u00e9todo 2. (Redirecci\u00f3n de la salida - error y est\u00e1ndar) comando &amp;&gt;&nbsp;<a href=\"https:\/\/hosting.airetech.es\/blog\/wiki\/uso-de-las-redirecciones-de-error-en-bash\/\" class=\"read-more\">Seguir leyendo<\/a>","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_monsterinsights_skip_tracking":false,"_monsterinsights_sitenote_active":false,"_monsterinsights_sitenote_note":"","_monsterinsights_sitenote_category":0,"footnotes":""},"categories":[10,6],"tags":[152,216,155,153,154],"class_list":["post-2232","post","type-post","status-publish","format-standard","hentry","category-linux","category-wiki","tag-bash","tag-linux","tag-stderr","tag-stdin","tag-stdout","cat-10-id","cat-6-id"],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/hosting.airetech.es\/blog\/wp-json\/wp\/v2\/posts\/2232","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/hosting.airetech.es\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/hosting.airetech.es\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/hosting.airetech.es\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/hosting.airetech.es\/blog\/wp-json\/wp\/v2\/comments?post=2232"}],"version-history":[{"count":8,"href":"https:\/\/hosting.airetech.es\/blog\/wp-json\/wp\/v2\/posts\/2232\/revisions"}],"predecessor-version":[{"id":2329,"href":"https:\/\/hosting.airetech.es\/blog\/wp-json\/wp\/v2\/posts\/2232\/revisions\/2329"}],"wp:attachment":[{"href":"https:\/\/hosting.airetech.es\/blog\/wp-json\/wp\/v2\/media?parent=2232"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/hosting.airetech.es\/blog\/wp-json\/wp\/v2\/categories?post=2232"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/hosting.airetech.es\/blog\/wp-json\/wp\/v2\/tags?post=2232"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}