Menu

SHELL doesn't proceed until process terminates

Anonymous
2016-09-12
2016-09-17
  • Anonymous

    Anonymous - 2016-09-12

    Hi, and THANKS for PC-BASIC! It's helping us continue running BASIC programs written in the 1980's on Windows 10! We updated from Windows XP (running BASICA.EXE in SP1 compatibility mode) recently, and noticed one minor difference:

    Our BASIC program uses the statement: SHELL "cmd /c start notepad "+PRINTER.FILE$

    Under BASICA.EXE on XP, the Notepad window would open up, and the BASIC program would continue on to the next statement. But under PC-BASIC the program pauses until the Notepad window is closed. Is there a command-line or INI setting that will adjust this behavior for us?

    Thanks again,
    Tim

     
  • Rob Hagemans

    Rob Hagemans - 2016-09-12

    Hi Tim, great that PC-BASIC is useful to you!

    Not sure about the SHELL statement - it's pretty much out of the control of PC-BASIC as it just sends commands to the operatin system. It does seem that the cmd /c is superfluous, since SHELL C$ basically does a cmd /c C$ anyway. Have you tried just SHELL "start notepad"+PRINTER.FILE$? Not sure if it works but it might be worth a try. I can't think of a command-line setting that would help - the --shell option in principle lets you choose another command prompt, but I think cmd and PowerShell are likely the only ones that will work on Windows.

    Rob

     
    • Anonymous

      Anonymous - 2016-09-16

      Thanks for your suggestions. SHELL "start notepad" also does not return control to PC-BASIC until the Notepad window is closed. PC-BASIC seems to always wait for the process to exit. In a cmd window, when you run "start notepad", you can type the next command into the cmd window while notepad is still running. So SHELL C$ doesn't seem to be the same as "cmd /c C$" when C$ = "start notepad".

      I found a work-around, but it uses PSEXEC from SysInternals.

      SHELL "psexec -accepteula -d notepad "+PRINTER.FILE$+" 2>NULL"

      The -d solves the issue by starting the notepad process and exiting immediately returning control to the BASIC program.

      BTW, the "-accepteula" and " 2>NULL" eliminate psexec's banner output showing version, copyright and author info. See http://forum.sysinternals.com/psexec-how-to-get-output-to-a-file-withou-banner_topic14936.html.

      I tried a couple different things with powershell.exe, but was unsuccessful, so to keep you from repeating my attempts, the following methods do not work:

      Powershell can launch a new process with the statement "Start-Process -NoNewWindow myprog.exe" in a .ps1 script file. To do it without a .ps1 file, you can run powershell like this from a cmd prompt:

      powershell -command "& { Start-Process -NoNewWindow notepad MyFile.txt }"

      and the Notepad window will open, and control will return immediately to the cmd window. Assigning this command string to a variable (including the double-quotes inserted as chr$(34)) and running it with SHELL in PC-BASIC results in the command string being output "& { Start-Process -NoNewWindow notepad MyFile.txt }". The command doesn't run, but PowerShell seems to be holding control behind the scenes until Enter is pressed.

      I also tried setting shell=powershell.exe in PC-BASIC's settings, and using SHELL C$ with C$ set equal to -command "& { Start-Process -NoNewWindow notepad MyFile.txt }" but an error is returned regarding unary operator "-".