Author Topic: Calling an external program - having difficulties  (Read 3433 times)

0 Members and 1 Guest are viewing this topic.

Offline FilipeEstima

  • Newbie
  • Posts: 63
    • View Profile
Calling an external program - having difficulties
« 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

Offline SMcNeill

  • QB64 Developer
  • Forum Resident
  • Posts: 3972
    • View Profile
    • Steve’s QB64 Archive Forum
Re: Calling an external program - having difficulties
« Reply #1 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.
https://github.com/SteveMcNeill/Steve64 — A github collection of all things Steve!

Offline FilipeEstima

  • Newbie
  • Posts: 63
    • View Profile
Re: Calling an external program - having difficulties
« Reply #2 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!

Offline SMcNeill

  • QB64 Developer
  • Forum Resident
  • Posts: 3972
    • View Profile
    • Steve’s QB64 Archive Forum
Re: Calling an external program - having difficulties
« Reply #3 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.  ;)
https://github.com/SteveMcNeill/Steve64 — A github collection of all things Steve!

Offline Pete

  • Forum Resident
  • Posts: 2361
  • Cuz I sez so, varmint!
    • View Profile
Re: Calling an external program - having difficulties
« Reply #4 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
Want to learn how to write code on cave walls? https://www.tapatalk.com/groups/qbasic/qbasic-f1/

Offline FilipeEstima

  • Newbie
  • Posts: 63
    • View Profile
Re: Calling an external program - having difficulties
« Reply #5 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!

Offline Pete

  • Forum Resident
  • Posts: 2361
  • Cuz I sez so, varmint!
    • View Profile
Re: Calling an external program - having difficulties
« Reply #6 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
Want to learn how to write code on cave walls? https://www.tapatalk.com/groups/qbasic/qbasic-f1/

Offline _vince

  • Seasoned Forum Regular
  • Posts: 422
    • View Profile
Re: Calling an external program - having difficulties
« Reply #7 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