Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Shell issues
#1
Hi,

When using Shell with no parameters the program displays a blank screen which cannot be exited
without going to Task Manager->Processes and manually right-click and end task!?

Instead I am using Shell "Cmd" to properly starting a dos-like window shell and prompt to exit.

Why is this? And does Linux/MacOsX require other than "Cmd" to load shell?

Should I otherwise use the following:

Code: (Select All)
Comspec$=Environ$("COMSPEC")
Shell Comspec$
Also, the Wiki says to use Shell "Cmd /C" or it may hang..

Thank you, Erik.

This is some code I have been using:

Code: (Select All)
' program to shell to window
Print "Enter shell command:";
Line Input x$
Call ShellSub(x$)
End

' subroutine to shell to dos
Sub ShellSub (x$)
   If x$ = "" Then
      Comspec$ = Environ$("COMSPEC")
      If Len(Comspec$) Then
         Shell Comspec$
      Else
         Shell "CMD"
      End If
   Else
      X = FreeFile
      Open "SHELL.BAT" For Output As #X
      Print #X, "@ECHO OFF"
      Print #X, x$
      Print #X, "PAUSE"
      Print #X, "EXIT"
      Close #X
      Shell "SHELL.BAT"
   End If
End Sub
Reply
#2
(05-05-2025, 03:03 AM)eoredson Wrote: When using Shell with no parameters the program displays a blank screen which cannot be exited
without going to Task Manager->Processes and manually right-click and end task!?

From reading the above, it sounds like you're writing a program such as this:
Code: (Select All)
SHELL

And then you mention this:
(05-05-2025, 03:03 AM)eoredson Wrote: Also, the Wiki says to use Shell "Cmd /C" or it may hang..

Looks to me like you wrote and answered yourself. What am I missing here?

If you read the CMD help info, you see this:

/C Carries out the command specified by string and then terminates...

If you're just looking to open a command window, and not have it automatically terminate, just do:

Code: (Select All)
SHELL "CMD"

That /C is for executing commands and closing after, so if you leave it blank, you execute nothing and then close. "CMD" alone should be all you need to open a command window and keep it open for whatever purpose.
Reply
#3
Although I may have answered my own post and it works!?

It doesn't explain the following:

1)why does shell w/o parameter hang?
2)what is the equivalent to CMD in Linux and MacOsX?
3)does or should comspec$ be used?

Thank you, Erik.
Reply
#4
(05-07-2025, 12:26 AM)eoredson Wrote: Although I may have answered my own post and it works!?

It doesn't explain the following:

1)why does shell w/o parameter hang?
2)what is the equivalent to CMD in Linux and MacOsX?
3)does or should comspec$ be used?

Thank you, Erik.

There isn't an exact one to one equivalent to CMD in Linux.  Depending on what you want to actually accomplish you want to use either xdg-open or the executable name
of your favorite xterm type program    (xterm, gterm, konsole    etc...)
Reply
#5
Shell by itself hangs because it waits for a exit code to continue and return back to your program.  Of course, if you just shell to nothing, there's nothing to return an exit code, and thus it just enters an endless loop waiting for an exit code that will never come.

See this little code snippet for an example:
Code: (Select All)
$Console:Only
Do
    count = count + 1
    Print count
    If count Mod 10 = 0 Then Shell "cmd"
Loop

Run that, it'll print 1 to 10 on the console.   
Then it'll wait for you to type something into the command line.  
Type "EXIT" so the shell ends.  
It'll then continue and print 11 to 20 on the console.
Where it'll then wait for the "EXIT" to be typed to end your use of the command line.

SHELL waits for whatever it shells to to end before it returns control back to QB64.  So a blank SHELL with nothing inside it can't send a termination code, so it's just going to wait forever and ever and ever....



COMSPEC$ doesn't need to be used.  Just SHELL "CMD" as I did above.  It really is that simple.
Reply
#6
(05-07-2025, 04:34 AM)SMcNeill Wrote: Shell by itself hangs because it waits for a exit code to continue and return back to your program.  Of course, if you just shell to nothing, there's nothing to return an exit code, and thus it just enters an endless loop waiting for an exit code that will never come.

See this little code snippet for an example:
Code: (Select All)
$Console:Only
Do
    count = count + 1
    Print count
    If count Mod 10 = 0 Then Shell "cmd"
Loop

Run that, it'll print 1 to 10 on the console.   
Then it'll wait for you to type something into the command line.  
Type "EXIT" so the shell ends.  
It'll then continue and print 11 to 20 on the console.
Where it'll then wait for the "EXIT" to be typed to end your use of the command line.

SHELL waits for whatever it shells to to end before it returns control back to QB64.  So a blank SHELL with nothing inside it can't send a termination code, so it's just going to wait forever and ever and ever....



COMSPEC$ doesn't need to be used.  Just SHELL "CMD" as I did above.  It really is that simple.
Ok, thanks. That's what I thought.
Reply
#7
since linux could be "many" operating systems to some people.  there are many terminal emulators.  some of them friendlier than others.

sadly must go through a list of possible emulators.  as was already said.  it's not reliable on some systems using "xdg-open" or other gag.  for example if an user wants to use "thunar" file manager.  but didn't choose xfce desktop environment.  this is possible in eg. cinnamon.  since "nemo" is slow as a hog and has other performance issues.  such as its failure to mark the current position when "page up" and "page down" keys are used.  the "example" command to open a terminal for the current directory.  works on "thunar" in xfce.  but fails when "thunar" is used in a different desktop.

on kde "konsole" is the only acceptable choice.  start the search with that one.  then go through others like "gnome-terminal".  "xfce-terminal".  "mate-terminal".  "qterminal" this is the one for lxqt.  might have to go through others which are lesser known.  such as "rox-terminal" a good one which sadly needs to be compiled on some systems.

a few users have this monster:

https://man.archlinux.org/man/urxvt.7

note that on debian/ubuntu this is called "rxvt-unicode".

this might be enough:

Code: (Select All)
xdg-open /path/to/the/folder
if not, as i've said in place of "xdg-open".  will have to put down the name of a terminal emulator existing in the system.

Code: (Select All)
mate-terminal --working-directory=/path/to/the/folder
this is an example for mate desktop.

will need to provide the folder.  but usually this is the user's home.

i wanted to answer the question here.  but was trying to use "bash" command in various ways and failed.  it must be through a terminal emulator.
Reply
#8
Sounds like alot of Shell functions when all I needed was:

MS-DOS  -  Command.com
Windows -  Cmd.exe

And Comspec usually returns one of the above..

Erik.
Reply




Users browsing this thread: 1 Guest(s)