Having trouble Windows command line SORT via SHELL
#11
(08-25-2023, 01:17 PM)SpriggsySpriggs Wrote: Should you be using two greater-than signs rather than one? I thought you only needed one for redirection. Maybe that's why it is saying you did it twice.
The >> means to redirect and append at the same time.
Software and cathedrals are much the same — first we build them, then we pray.
QB64 Tutorial
Reply
#12
(08-24-2023, 02:42 PM)GTC Wrote: My program generates 12 output files that then need to be sorted, and I'd rather do those sorts from within the app (via SHELL) than have to use SORT standalone from the command line afterwards.

Here's an example of how I'm calling it:

Sort_Command$ = "SORT " + "x.x" + " >> " + "y.y"
SHELL Sort_Command$

If I type that sort command on the command line I get y.y as a sorted version of x.x ... which is desired.

However when executed via SHELL a message flashes up in the output window (too fast to read before a blank window replaces it), and no sort occurs.

I have used SHELL previously with other commands and experienced no problems.

Is there a way of directing the contents of the output window to a file, so that I can read whatever is being shown on that?

Add a
SLEEP
to see the command before the shell exits maybe too, so you can see it.

Also in a real pinch
CTRL+S
will stop flow control and pause if you catch it in time, and
CTRL+Q
will resume. (I think that's the right order, I might have those flip-flopped).

Also @TerryRitchie has good advice about trying from batch file. If you still see the window shutting on you before you can read it in batch file you call your QB program from, use a
pause
there at the very end (same effect as QB64's
SLEEP
- will make you press a key - and even politely ask you to do so).

What you're asking for for redirection should be possible in QB64 - it's called
stdio
(where i = input, o = output) there is also a
stderr
which is an error stream for info/warning/failures. By default windows supports that. You see it above with your
>>
redirection in your
Sort_Command$
. That means to append the output of command
SORT x.x
to the file
y.y
-- if you want to get a fresh copy each time use 1
>
instead, which will reset/erase the file vs. append it.

Hope this helps!
grymmjack (gj!)
GitHubYouTube | Soundcloud | 16colo.rs
Reply
#13
Like I say, try it with quotes around the file names.  

Code: (Select All)
$Console:Only
Sleep
sort$ = "sort " + Chr$(34) + "input.txt" + Chr$(34) + " >> " + Chr$(34) + "output.txt" + Chr$(34)
Print sort$
Shell sort$
Sleep
System

It honestly sounds to me as if you're trying to use a file which the command line is seperating apart into multiple components such as "My Input File.txt".  <-- With the spaces in that file, the command line will parse it as "My", "Input", "File.txt", which is three components rather than one. 

Enclose your file name in quotes and see how things work for you.

******************************

Step 2:  Make certain that if on newer versions of Windows, you're going to a CMD window and not a Terminal as they're not always the same in how they handle things.
Reply
#14
(08-25-2023, 02:53 PM)SMcNeill Wrote: Like I say, try it with quotes around the file names.  

Code: (Select All)
$Console:Only
Sleep
sort$ = "sort " + Chr$(34) + "input.txt" + Chr$(34) + " >> " + Chr$(34) + "output.txt" + Chr$(34)
Print sort$
Shell sort$
Sleep
System

It honestly sounds to me as if you're trying to use a file which the command line is seperating apart into multiple components such as "My Input File.txt".  <-- With the spaces in that file, the command line will parse it as "My", "Input", "File.txt", which is three components rather than one. 

Enclose your file name in quotes and see how things work for you.

******************************

Step 2:  Make certain that if on newer versions of Windows, you're going to a CMD window and not a Terminal as they're not always the same in how they handle things.
Good thinking @SMcNeill

Try filename without spaces to eliminate the need for quotes possibly too.
grymmjack (gj!)
GitHubYouTube | Soundcloud | 16colo.rs
Reply
#15
(08-25-2023, 01:17 PM)SpriggsySpriggs Wrote: Should you be using two greater-than signs rather than one? I thought you only needed one for redirection. Maybe that's why it is saying you did it twice.

(08-25-2023, 01:55 PM)TerryRitchie Wrote:
(08-25-2023, 01:17 PM)SpriggsySpriggs Wrote: Should you be using two greater-than signs rather than one? I thought you only needed one for redirection. Maybe that's why it is saying you did it twice.
The >> means to redirect and append at the same time.

Either redirect operator results in the same error outcome.
Reply
#16
(08-25-2023, 02:53 PM)SMcNeill Wrote: [snip]

Enclose your file name in quotes and see how things work for you.
Have done that, to no avail.
Reply
#17
(08-25-2023, 02:53 PM)SMcNeill Wrote: [snip]

Step 2:  Make certain that if on newer versions of Windows, you're going to a CMD window and not a Terminal as they're not always the same in how they handle things.

By going to a CMD window rather than a Terminal, are you referring to this?

"QB64 automatically uses CMD /C when using SHELL, but it is allowed in a command string. Note: CMD alone may lock up program.
Some commands may not work without adding CMD /C to the start of the command line."

I tried adding CMD /C to no avail.
Reply
#18
@GTC could you share your program? Or at least a reproducible part that we can get the failure to happen with?
grymmjack (gj!)
GitHubYouTube | Soundcloud | 16colo.rs
Reply
#19
(08-25-2023, 10:48 PM)grymmjack Wrote: @GTC could you share your program? Or at least a reproducible part that we can get the failure to happen with?
Yes, I agree. We're just going to keep going in circles without something to debug.
Software and cathedrals are much the same — first we build them, then we pray.
QB64 Tutorial
Reply
#20
Worked around. Instead of dealing with directory name strings in the SHELL command, I execute a BAT file and CD to the working directory ahead of the SORTs.

Now ... if you've been a programmer in a commercial environment for a reasonable length of time, you'll be aware of the adage "The user doesn't know what he wants until he sees what he gets".

In my case the user now wants some post-sort processing so I'll use a bubble or quick sort internally.

Thanks for all of the tips, guys. Heart
Reply




Users browsing this thread: 11 Guest(s)