QB64.org Forum

Active Forums => QB64 Discussion => Topic started by: FilipeEstima on February 24, 2019, 03:10:03 pm

Title: Calling an external program - having difficulties
Post by: FilipeEstima on February 24, 2019, 03:10:03 pm
Hello fellows, two questions here.

1) I am trying to call an external command-line program and have the result going back to my QB64 program. Is it true the only way I can capture the external program printed results is by redirecting its output to a file and then opening said file in my program? Isn't there another way?

2) I am trying to make crc32.exe to work with this:

Code: QB64: [Select]
  1. SHELL _HIDE "crc32 test.txt -nf >tempfile.txt"

But tempfile.txt is never created. What am I doing wrong? crc32.exe can be found here -> http://esrg.sourceforge.net/utils_win_up/md5sum
Title: Re: Calling an external program - having difficulties
Post by: SMcNeill on February 24, 2019, 03:29:24 pm
First thing to do when debugging SHELL calls is to remove the _HIDE portion of the command.  Let the console window pop up so you can read the screen and see what the glitch might be (such as “command not recognized” or “can’t create file”).  Then you can take steps to remedy the issue and add _HIDE back to the SHELL statement once it’s working.
Title: Re: Calling an external program - having difficulties
Post by: FilipeEstima on February 24, 2019, 03:36:12 pm
Yes, I tried that; the problem is that window opens and closes immediately, I don't have enough time to read what is written!
Title: Re: Calling an external program - having difficulties
Post by: SMcNeill on February 24, 2019, 03:40:12 pm
Add a console to your program.  It’ll shell command there.

http://www.qb64.org/wiki/$CONSOLE

Generally just add two lines to the top of your code for debugging:
$CONSOLE
_CONSOLE ON

That should fix the issue with it closing on you.  ;)
Title: Re: Calling an external program - having difficulties
Post by: Pete on February 24, 2019, 03:40:58 pm
Well, I'll have to assume you have the correct SHELL usage for your external program, with -nf switch. If so, here's one possibly; you need to include the directory of that external exe file.

For Windows in the registry, like Notepad, you can get away with SHELL _HIDE "Notepad mytext.txt" Windows can find the path to start Notepad through the Registry. For external programs that are not registered, yo need to either supply the path, or have that external program in your QB64 folder, along with QB64.exe.

So maybe try: SHELL _HIDE "c:\mycrc32folder\crc32 test.txt -nf >tempfile.txt" where c:\mycrc32folder is the name of your drive and folder that contains crc32.exe.

You can also try adding START as in: SHELL _HIDE "START c:\mycrc32folder\crc32 test.txt -nf >tempfile.txt"

To make things simple, you could copy crc32.exe to your QB64 folder. SHELL knows yo are in that folder, because it's the local folder.

One other note with folder names. Take the Program Files folder, for example. It contains a space. Names with spaces must be enclosed in quotation marks. So it it was located in the C:\Programs File\crc32.exe, you would need to write it as: SHELL _HIDE CHR$(34) + "C:\programs file\crc32" + CHR$(34) + " test.txt -nf >tempfile.txt"

This may not be the problem, but it is worth looking into. Sorry, I have no familiarity with the program you are using.

Pete
Title: Re: Calling an external program - having difficulties
Post by: FilipeEstima on February 24, 2019, 03:45:10 pm
Dang! From https://qb64.org/wiki/SHELL

"Note: Some commands may not work without adding CMD /C to the start of the command line"

This solved the problem:

Code: QB64: [Select]
  1. SHELL _HIDE "CMD /C crc32 test.txt -nf >tempfile.txt"

Thanks Pete and SMcNeill for trying to help!
Title: Re: Calling an external program - having difficulties
Post by: Pete on February 24, 2019, 04:37:49 pm
Before QB64 came along, SHELL in QBasic, QuickBASIC 4.5, and PDS AKA QuickBASIC 7.0, all required CMD /C in XP and Command /C in Windows 98 and previous Windows OS's. START was also used, and had parameters, like /min /max to start the program minimized or maximized. Some programs can still be manipulated that way, like Notepad.

I'm glad you found the fix. Good luck with your project!

Pete
Title: Re: Calling an external program - having difficulties
Post by: _vince on February 24, 2019, 11:51:00 pm
Looks like you just need a CRC32 function.  Is there any reason you don't want to write your own one in QB64? Make an attempt and we can help. If you're concerned about speed you can also use one with DECLARE LIBRARY