Output redirection

We have an application here that does some table queries and then prints the result on screen. I do not have the code of this application (which i will just call "queryCommand"), but what it does is that you call it with some parameters and it prints some info about the query and then the registries that it gets. I need to print the results of this command on a file. I have tried:

queryCommand [parameters] > file.txt

But what happens is that I get the query info on the file, but all the registries that come after are still printed on screen and not in the file. As I said, I don't have the code of this "queryCommand" so i don't know what it does to print results. If anyone could help me i would appreciate it. Thanks in advance.

Details:

=>Command with no output redirection:

l65r[/u/visitas] srm_aplx L65r NSGT 107354410383V0003AEC

outputs on screen:

Retorno de srm() : (hexa) 0  (dec) 0
Status     : 00
largo_data : 7769
Datos      :
00N00460165AEC00000

=>Command with output redirectio:

l65r[/u/visitas] srm_aplx L65r NSGT 107354410383V0003AEC > out.txt

outputs on screen:

00N00460165AEC00000

and only the first part goes to out.txt

did you try something like

queryCommand [parameters] >file.txt 2>&1

If you already are in a prompt of a program (like in sqlplus, or like in a debugger gdb, ...) maybe you should get a manual of the available command line : they may be some specific instruction to enter (like spool name .... spool off in sqlplus) to generate the expected log file.

1 Like
queryCommand [parameters] > file.txt 2>&1

When I try this there is nothing in the file and on screen.
I'm connecting to a Unix machine that uses ksh to run the command.

try :

script file.txt
queryCommand [parameters]
exit

and check the content of file.txt

you could also give a try to

queryCommand [parameters] | tee -a file.txt

did you try without space:

queryCommand [parameters] >file.txt 2>&1

any error message ?

also try

2>file.err queryCommand [parameters] >file.txt
1 Like

Works =]
Thank you very much !

It worked with

queryCommand [parameters] >file.txt 2>&1

Just to know... what is the 2>&1 for ?

Edit: nvm i looked it up, so i guess the application is throwing the registries on the standard error stream (kinda odd) and you merged them both with the 2>&1. Thanks again.

If needed, you can separate them with - for example :

queryCommand [parameters] >file.txt 2>file.err
1 Like