Routing stderr output from cmd statements

Reply
Occasional Contributor
Posts: 15

Routing stderr output from cmd statements

Hi,

I read from websites that having "2>Nul" in the end of cmd statement will route stderr output in windows. This works for me in below statement.

filename dirinfo pipe 'dir &path 2> Nul';

But it does not work in SCL system function with xcopy cmd statement. For eg. rc=system('xcopy <filename> <target folder> 2> Nul');

After I added 2>Nul in the end of the statement, return code rc is 4 and copy is not happening (usually on successful copy rc was 0).

Do you have any suggesstion to route stderr output from cmd statements in system function?

Thanks in advance!

-Sudharsanan

Valued Guide
Posts: 3,208

Re: Routing stderr output from cmd statements

AF/SCL is behaving different I some aspects.  It will build a buffer that is processed by Scl before it is given to the sas-processor.

You did not post your excact coding. When your are using SAS(R) Component Language 9.4: Reference, Second Edition (scl function) . 
xcopy itself should work as you described. Sure the statement that is generated is correct? No other changes? 

---->-- ja karman --<-----
Occasional Contributor
Posts: 15

Re: Routing stderr output from cmd statements

Thanks for your reply.

I have not done any other change than adding "2>nul" to the end of of the xcopy statement.

The code I had was working rc=system('xcopy <filename> <target folder> '); by copying files and rc=0.

When I changed it as rc=system('xcopy <filename> <target folder> 2>nul '); it was not working and rc=4.

Valued Guide
Posts: 3,208

Re: Routing stderr output from cmd statements

Well <filename>  and <target folder> are for sure not the real values, something is changing that.

If that something is doing a parse and change the < > characters than that something can also change your 2> null.   

---->-- ja karman --<-----
Occasional Contributor
Posts: 15

Re: Routing stderr output from cmd statements

Hi Karman,

Thanks.

I have variable for <filename> and <target folder>. They have quotes and it was working without "2>nul" added in the end of the statment.

I have tested in many different cmd statement that having "2>nul" in SCL System function does not work.

The same issue happens in SAS/Base System function also.

For me "2>nul" works only in pipe statement with dir cmd command.

Please let me know if any suggestion.

Valued Guide
Posts: 3,208

Re: Routing stderr output from cmd statements

For the SAS/Base language I know the issues well  with all quutin issues

SAS(R) 9.4 Macro Language: Reference See the different meanings of special chars. Al lot of work when they are involved and needing bypasses. The difference between single and double quotes for strings can be very important. There is somewhere interference of symbols

You did not show the command (put statement) in full glory or other debugging action.

The usage of this as SCL function or as modified (submit block) SAS-base processing I am also not seeing... 

The SAS-base is probably easier to debug focus on the quoting remarks.

---->-- ja karman --<-----
Ask a Question
Discussion stats
  • 5 replies
  • 228 views
  • 0 likes
  • 2 in conversation