Redirect stderr to stdout in C shell

The csh shell has never been known for its extensive ability to manipulate file handles in the redirection process. You can redirect both standard output and error to a file with: xxx >& filename but that’s not quite what you were after, redirecting standard error to the current standard output. However, if your underlying operating … Read more

How do I call the PowerShell CLI robustly, with respect to character encoding, input and output streams, quoting and escaping?

PowerShell CLI fundamentals: PowerShell editions: The CLI of the legacy, bundled-with-Windows Windows PowerShell edition is powershell.exe, whereas that of the cross-platform, install-on-demand PowerShell (Core) 7+ edition is pwsh.exe (just pwsh on Unix-like platforms). Interactive use: By default, unless code to execute is specified (via -Command (-c) or -File (-f, see below), an interactive session is … Read more

How do I redirect output to a file with CreateProcess?

The code below creates a console-less process with stdout and stderr redirected to the specified file. #include <windows.h> int _tmain(int argc, _TCHAR* argv[]) { SECURITY_ATTRIBUTES sa; sa.nLength = sizeof(sa); sa.lpSecurityDescriptor = NULL; sa.bInheritHandle = TRUE; HANDLE h = CreateFile(_T(“out.log”), FILE_APPEND_DATA, FILE_SHARE_WRITE | FILE_SHARE_READ, &sa, OPEN_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL ); PROCESS_INFORMATION pi; STARTUPINFO si; BOOL ret = … Read more

UTF-8 output from PowerShell

Not an expert on encoding, but after reading these… http://blogs.msdn.com/b/powershell/archive/2006/12/11/outputencoding-to-the-rescue.aspx http://technet.microsoft.com/en-us/library/hh847796.aspx http://www.johndcook.com/blog/2008/08/25/powershell-output-redirection-unicode-or-ascii/ … it seems fairly clear that the $OutputEncoding variable only affects data piped to native applications. If sending to a file from withing PowerShell, the encoding can be controlled by the -encoding parameter on the out-file cmdlet e.g. write-output “hello” | out-file “enctest.txt” … Read more