Ignoring exit code from "system" on Windows

Is there a way to ignore the exit code (and therefore 'os error) and get the stdout+stderr of a process on Windows? On Linux the following works:
system"(program 2>&1; true)"

maybe set errorlevel=0

jack@TP C:\Users\jack

> q                                                                                          

KDB+ 3.1 2014.08.22 Copyright (C) 1993-2014 Kx Systems                                       

w32/ 4()core 4095MB jack tp 192.168.2.12 NONEXPIRE                                           

                                                                                             

q)\dir …

File Not Found

'os

q)\dir … & set errorlevel=0                                                                

 Volume in drive C is Windows7_OS                                                            

 Volume Serial Number is 545A-BF90                                                           

                                                                                             

 Directory of C:\Users\jack\trade...                                                        

                                                                                             

File Not Found                                                                               

q)                                                                                           

                                                                                             

                                                                                             

                                                                                             

                                                                                             

On 27 September 2015 at 17:53, Péter Györök <gyorokpeter1@gmail.com> wrote:

Is there a way to ignore the exit code (and therefore 'os error) and get the stdout+stderr of a process on Windows? On Linux the following works:
system"(program 2>&1; true)"


Submitted via Google Groups

Is there a way to also capture the stderr from the command?

q)a:system"dir foo & set errorlevel=0 2>&1"
 Volume in drive D has no label.
 Volume Serial Number is E2F8-5938

 Directory of D:\Projects\q

File Not Found

q)a:system"dir foo 2>&1 & set errorlevel=0"
 Volume in drive D has no label.
 Volume Serial Number is E2F8-5938
 
 Directory of D:\Projects\q

File Not Found

I would expect the stderr to go into the variable instead of printed to the console.

q)a:system"dir util.q"
q)a
" Volume in drive D has no label."
" Volume Serial Number is E2F8-5938"
“”
" Directory of D:\Projects\q"
“”
“2015.08.23.  13:05               811 util.q”
"               1 File(s)            811 bytes"
"               0 Dir(s)  108\377448\377792\377576 bytes free"

  1. szeptember 27., vasárnap 11:11:53 UTC+2 id?pontban effbiae a következ?t írta:

maybe set errorlevel=0

jack@TP C:\Users\jack

> q                                                                                          

KDB+ 3.1 2014.08.22 Copyright (C) 1993-2014 Kx Systems                                       

w32/ 4()core 4095MB jack tp 192.168.2.12 NONEXPIRE                                           

                                                                                             

q)\dir …

File Not Found

'os

q)\dir … & set errorlevel=0                                                                

 Volume in drive C is Windows7_OS                                                            

 Volume Serial Number is 545A-BF90                                                           

                                                                                             

 Directory of C:\Users\jack\trade...                                                        

                                                                                             

File Not Found                                                                               

q)                                                                                           

                                                                                             

                                                                                             

                                                                                             

                                                                                             

To: =?utf-8?b?UMOpdGVyIEd5w7Zyw7Zr?= , Kdb+ Personal Developers
Can't you just error trap in kdb?

@[system;cmd;{}]

From: P=C3=A9ter Gy=C3=B6r=C3=B6k
Sent: Sunday, September 27, 2015 00:53
To: Kdb+ Personal Developers
Reply To: personal-kdbplus@googlegroups.com
Subject: [personal kdb+] Ignoring exit code from "system" on Windows

Is there a way to ignore the exit code (and therefore 'os error) and get the stdout+stderr of a process on Windows? On Linux the following works:
system"(program 2>&1; true)"


Submitted via Google Groups

That swallows the error but also the useful output.

  1. szeptember 27., vasárnap 19:32:10 UTC+2 id?pontban David Demner a következ?t írta:

Can’t you just error trap in kdb?

@[system;cmd;{}]

|

From: Péter Györök

Sent: Sunday, September 27, 2015 00:53

To: Kdb+ Personal Developers

Reply To: personal…@googlegroups.com

Subject: [personal kdb+] Ignoring exit code from “system” on Windows

|

Is there a way to ignore the exit code (and therefore 'os error) and get the stdout+stderr of a process on Windows? On Linux the following works:
system"(program 2>&1; true)"


Submitted via Google Groups

This works on Windows:
q)system"program 2>&1 || echo."

That still doesn’t get the useful output:

q)system"dir foo 2>&1 || echo."
 Volume in drive D has no label.
 Volume Serial Number is E2F8-5938

 Directory of D:\Utility\q

File Not Found
," "

Only one space is returned, same as system"echo.".

  1. október 2., péntek 15:38:41 UTC+2 id?pontban Igor Korkhov a következ?t írta:

This works on Windows:
q)system"program 2>&1 || echo."

use cygwin’s true.exe instead of cmd’s echo. assume goodFile exists and badFile doesnt.

system “dir badFile 1>stdout 2>stderr || c:\cygwin64\bin\true.exe”

system “dir goodFile 1>stdout 2>stderr || c:\cygwin64\bin\true.exe”

read0 `:stdout

read0 `:stderr

Sorry, by bad. You should use parentheses:
system"(dir foo 2>&1 || echo.)"

HTH