Author Topic: A strange behavior of SHELL and CHAIN  (Read 4817 times)

0 Members and 1 Guest are viewing this topic.

Offline krovit

  • Forum Regular
  • Posts: 179
    • View Profile
A strange behavior of SHELL and CHAIN
« on: October 13, 2020, 03:04:18 am »
Hi !

In the test I attach I try to copy some files from one folder to another.

When the files are in the same folder everything seems to work coem we would expect.

When folders are different the jump from one exe to another chain and shell seems not to work properly (why is the window not deleted and the writings of the two programs coexist?). TMP files are also not deleted.

in the specific case of my application I can not copy files from one folder to another by launching an executable that is located in a third folder.

  [ You are not allowed to view this attachment ]  

Nothing is easy, especially when it appears simple (and nothing could be as dangerous as trying to do good to others)

Offline krovit

  • Forum Regular
  • Posts: 179
    • View Profile
Re: A strange behavior of SHELL and CHAIN
« Reply #1 on: October 13, 2020, 07:13:15 am »
Uh... after countless tests I think you can confirm that it's a bug.

The CHAIN command causes an incomprehensible temporary file of type chain000.tmp to be constructed in the folder in which it is executed, without completing the operation.

The error occurs when the executable is in an folder and you are asked to operate in another folder.

Nothing is easy, especially when it appears simple (and nothing could be as dangerous as trying to do good to others)

FellippeHeitor

  • Guest
Re: A strange behavior of SHELL and CHAIN
« Reply #2 on: October 13, 2020, 07:15:13 am »
Don't modernize chain. It is there for older programs to be ressurrected, not for new ones to be written. Just use shell. Or better still, join your modules so you will have a single binary.
« Last Edit: October 13, 2020, 07:16:36 am by FellippeHeitor »

Offline krovit

  • Forum Regular
  • Posts: 179
    • View Profile
Re: A strange behavior of SHELL and CHAIN
« Reply #3 on: October 14, 2020, 06:33:47 am »
Thank you Felliippe

there is at least one case in which certain functions cannot be included within the application and is when the procedure should delete itself.

I needed chain just to launch a microprogram or batch file that would erase some things including the main program.

Patience! However the concept of dividing the program into so many smaller programs in practice was not bad.

Nothing is easy, especially when it appears simple (and nothing could be as dangerous as trying to do good to others)

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: A strange behavior of SHELL and CHAIN
« Reply #4 on: October 14, 2020, 01:34:07 pm »
Quote
there is at least one case in which certain functions cannot be included within the application and is when the procedure should delete itself.

Interesting, I have dabbled in ideas like this. How do you write a program on the fly, have QB64 compile and run it even eventually kill it while in the middle of another running QB64 program?

I could do that with ease with QB4.5 and DOS back when QB was interpreted.

Offline SMcNeill

  • QB64 Developer
  • Forum Resident
  • Posts: 3972
    • View Profile
    • Steve’s QB64 Archive Forum
Re: A strange behavior of SHELL and CHAIN
« Reply #5 on: October 14, 2020, 03:41:31 pm »
Interesting, I have dabbled in ideas like this. How do you write a program on the fly, have QB64 compile and run it even eventually kill it while in the middle of another running QB64 program?

I could do that with ease with QB4.5 and DOS back when QB was interpreted.

Try something like this:

Code: QB64: [Select]
  1. OPEN "HW.bas" FOR OUTPUT AS #1
  2. PRINT #1, "PRINT "; CHR$(34); "Hello World"; CHR$(34)
  3. SHELL _HIDE "qb64 -c " + CHR$(34) + "HW.bas" + CHR$(34)
  4. SHELL _DONTWAIT "HW.exe"
  5. PRINT "Compiled and ran independent HELLO WORLD program."
  6. PRINT "Press <ANY KEY> to terminate HELLO WORLD program."
  7. SHELL _HIDE _DONTWAIT "taskkill /F /IM HW.exe"
  8. PRINT "Program terminated.  Press <ANY KEY> to terminate this program."
  9.  
https://github.com/SteveMcNeill/Steve64 — A github collection of all things Steve!

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: A strange behavior of SHELL and CHAIN
« Reply #6 on: October 14, 2020, 03:49:10 pm »
Try something like this:

Code: QB64: [Select]
  1. OPEN "HW.bas" FOR OUTPUT AS #1
  2. PRINT #1, "PRINT "; CHR$(34); "Hello World"; CHR$(34)
  3. SHELL _HIDE "qb64 -c " + CHR$(34) + "HW.bas" + CHR$(34)
  4. SHELL _DONTWAIT "HW.exe"
  5. PRINT "Compiled and ran independent HELLO WORLD program."
  6. PRINT "Press <ANY KEY> to terminate HELLO WORLD program."
  7. SHELL _HIDE _DONTWAIT "taskkill /F /IM HW.exe"
  8. PRINT "Program terminated.  Press <ANY KEY> to terminate this program."
  9.  

Thanks Steve!  I will look into this when not so swamped. Had a setback with Knapsack problem and a revision for Hi Lo Game with no starting secret number that wipes the smirk off the Giant's smile, well most of it, still testing... but
I bet @krovit and @Tommy_81  will be interested in this too!

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: A strange behavior of SHELL and CHAIN
« Reply #7 on: October 16, 2020, 03:10:05 pm »
Thanks Steve!  I will look into this when not so swamped. Had a setback with Knapsack problem and a revision for Hi Lo Game with no starting secret number that wipes the smirk off the Giant's smile, well most of it, still testing... but
I bet @krovit and @Tommy_81  will be interested in this too!

I am just getting around to playing with this code and am wondering about 2 lines of code:
line 4&5,  qb64 -c  looks like a switch to just compile -c the file to follow HW.bas in this case, what are other switches that QB64 has? I tried looking up in Wiki and had 0 luck.

line 11:
SHELL _HIDE _DONTWAIT "taskkill /F /IM HW.exe"
hmm... this is probably a Windows thing, can you translate what it's saying and offer other switch options that might be useful or refer me to Windows reference. It is Windows, isn't it?

So if I do get something going with code, it's only going to work for Windows users?





Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: A strange behavior of SHELL and CHAIN
« Reply #8 on: October 16, 2020, 03:23:35 pm »
OK found this:
https://docs.microsoft.com/en-us/windows-server/administration/windows-commands/taskkill

And I guess that is complete set of relevant and useful switches for that taskkill line.

FellippeHeitor

  • Guest
Re: A strange behavior of SHELL and CHAIN
« Reply #9 on: October 16, 2020, 03:24:56 pm »
Use qb64 /? or qb64 --help in the command line to check the available command line switches. We can start a new thread to discuss any of them if you feel like.
« Last Edit: October 16, 2020, 03:30:09 pm by FellippeHeitor »

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: A strange behavior of SHELL and CHAIN
« Reply #10 on: October 16, 2020, 03:27:31 pm »
Use qb64 /? or qb64 --help in the command line to check the available command line switches.

Good! thanks @FellippeHeitor

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: A strange behavior of SHELL and CHAIN
« Reply #11 on: October 16, 2020, 08:35:16 pm »
Try something like this:

Code: QB64: [Select]
  1. OPEN "HW.bas" FOR OUTPUT AS #1
  2. PRINT #1, "PRINT "; CHR$(34); "Hello World"; CHR$(34)
  3. SHELL _HIDE "qb64 -c " + CHR$(34) + "HW.bas" + CHR$(34)
  4. SHELL _DONTWAIT "HW.exe"
  5. PRINT "Compiled and ran independent HELLO WORLD program."
  6. PRINT "Press <ANY KEY> to terminate HELLO WORLD program."
  7. SHELL _HIDE _DONTWAIT "taskkill /F /IM HW.exe"
  8. PRINT "Program terminated.  Press <ANY KEY> to terminate this program."
  9.  

@SMcNeill

I can't seem to get the little proggie to compile, I tried all kinds of delays in case it needed more time writing or compiling but no luck.

Disappointing, had big plans for this.

Think I'll try batch file, haven't written one of those in ages.
« Last Edit: October 16, 2020, 08:37:42 pm by bplus »

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: A strange behavior of SHELL and CHAIN
« Reply #12 on: October 16, 2020, 09:49:45 pm »
The bas file has to be in QB64.exe folder :P

Guess I need some way to get QB64.exe in the PATH but that's not going to work for others :P

Offline SMcNeill

  • QB64 Developer
  • Forum Resident
  • Posts: 3972
    • View Profile
    • Steve’s QB64 Archive Forum
Re: A strange behavior of SHELL and CHAIN
« Reply #13 on: October 16, 2020, 10:18:26 pm »
The bas file has to be in QB64.exe folder :P

Guess I need some way to get QB64.exe in the PATH but that's not going to work for others :P

Well, for that much, can you even guarantee that “others” have a copy of QB64 on their machine?  Many times, we have to code for our own set-ups, and let the next guy sort out what little tweaks/paths/folder changes are necessary for usage on their systems. 
https://github.com/SteveMcNeill/Steve64 — A github collection of all things Steve!

Offline krovit

  • Forum Regular
  • Posts: 179
    • View Profile
Re: A strange behavior of SHELL and CHAIN
« Reply #14 on: October 17, 2020, 03:36:01 pm »
Thank you, SMcNeill (and all the others who intervened)

The code you proposed is interesting and suggests some ideas like using Windows to delete or close a file (in addition to the usual batch DOS commands)

It would be a nice code of the Impossible Mission type: "This message will self-destruct in 30 seconds..."

___
Programming is a creative activity that stimulates imagination (and damns your soul)...
Nothing is easy, especially when it appears simple (and nothing could be as dangerous as trying to do good to others)