WinBatch® Technical Support Forum

All Things WinBatch => WinBatch => Topic started by: mueer01 on July 07, 2016, 01:35:35 AM

Title: runshell question
Post by: mueer01 on July 07, 2016, 01:35:35 AM
Hello,

I want to sort a file (c:\tmp\aaa.txt) with the runshell command. If I try this:

runshell("sort", "c:\tmp\aaa.txt", "c:\tmp", @NORMAL, @WAIT)

I see the sorted output scrolling through the DOS box (for a second).
But I need the output sent to c:\tmp\bbb.txt. So I tried this:

runshell("sort", "c:\tmp\aaa.txt > c:\tmp\bbb.txt", "c:\tmp", @NORMAL, @WAIT)

This does not work, I get nothing.

Is it possible at all?

Regards,
Erhard

Title: Re: runshell question
Post by: mueer01 on July 07, 2016, 06:48:37 AM
problem solved.

I created a mysort.bat dynamically with the complete sort command in it
then run the mysort.bat file

- close -
Title: Re: runshell question
Post by: td on July 07, 2016, 06:59:17 AM
You don't need to use the command shell's 'sort' command to sort a file with WinBatch and the topic of redirecting command shell stdout to a file is covered multiple time with multiple solutions in the Tech Database.  If you do want to use the command, the following is likely simpler and faster than just redirecting stdout or using a bat file:
Code (winbatch) Select
strCmd = Environment("COMSPEC")
RunShell(strCmd,"/c sort c:\temp\Junk.txt /o c:\temp\sortedjunk.txt", '', @Normal, @Wait)