以下のように、スクリプト自体の中から標準エラーと標準出力をリダイレクトすることが可能である。代わりバッチ - バッチスクリプト自体からstderrとstdoutをどのようにリダイレクトできますか? Unixシェルスクリプトで
test.sh
:
#!/bin/ksh
# script_name: test.sh
export AUTO_LOGFILE=`basename $0 .sh`.log
# stdout and stderr Redirection. This will save the old stdout on FD 3, and the old stderr on FD 4.
exec 3>&0 4>&1 >>$AUTO_LOGFILE 2>&1
echo "Hello World"
# The above echo will be printed to test.log
は実際に、test.shを単に実行することができますof:
test.sh >> test.log 2>&1
私は同様のバッチスクリプトを実行しようとしています。私のバッチコードは以下の通りです:
@echo off & setlocal enableextensions enabledelayedexpansion
REM script_name=test.bat
set AUTO_LOGFILE=%~n0.log
REM How to do the stdout and stderr redirection from within the script itself here?
バッチスクリプト自体からstderrとstdoutをリダイレクトする方法はありますか?
exec 3>&0 4>&1 >>$AUTO_LOGFILE 2>&1
あなたの質問はこれから重複しては:[それは、スクリプト内のバッチファイルの出力をリダイレクトすることは可能ですか?] [1] [1]:http://stackoverflow.com/questions/4607390/is-it-possible-the-output-of-output-of-a-batch-file-inside-the-script – Mac
@Mac I多くのコマンドを実行し、スクリプトの後半部分で多くのサブルーチンを呼び出す必要があります。私はあなたが提供したリンクの答えに記載されているように、単に関数testitoutでそれを行うことはできません。 –
これについてはわかりませんが、他のサブルーチンを呼び出すメインと同じように、サブルーチンがあった場合、それは機能しませんか? – Mac