Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
AI does a good job of analyzing code
#3
(04-25-2024, 03:50 PM)bplus Wrote: ask it to give a couple of handy examples to demo using the code

Quote:Here is an example of how to use the `pipecom` function in QB64 to execute an external command and capture its output:

```basic
DIM output AS STRING, error AS STRING
DIM exitcode AS INTEGER

exitcode = pipecom("dir", output, error)

IF exitcode = 0 THEN
    PRINT "Command executed successfully."
    PRINT "Output: " & output
ELSE
    PRINT "Command failed with exit code: " & STR$(exitcode)
    PRINT "Error: " & error
END IF
```

In this example:

1. We declare three variables: `output` to store the standard output of the command, `error` to store the standard error output, and `exitcode` to store the exit code of the command.

2. We call the `pipecom` function, passing in the command "dir" to execute, and the `output` and `error` variables to capture the output and error streams respectively.

3. The function returns the exit code of the command in `exitcode`.

4. We check the exit code - if it's 0, the command executed successfully, so we print the output. Otherwise, we print the exit code and error stream.

This allows running arbitrary commands and capturing their output within a QB64 program, which can be useful for tasks like executing system commands, parsing command output, or handling errors from external processes[1].

Citations:
[1] https://qb64.com
[2] https://en.wikipedia.org/wiki/QB64
[3] https://wiki.qb64.dev/qb64wiki/index.php/QB64_FAQ
[4] https://www.youtube.com/watch?v=6kn-N_-eycg
[5] https://qb64.com/wiki.html
The noticing will continue
Reply


Messages In This Thread
RE: AI does a good job of analyzing code - by SpriggsySpriggs - 04-25-2024, 04:15 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  VS Code and Qb64 pe Unseen Machine 6 755 09-03-2025, 09:42 PM
Last Post: grymmjack
  has anyone had ChatGPT write QB64 code yet? madscijr 13 2,993 08-23-2025, 09:15 AM
Last Post: doppler
  liquid code experiment madscijr 3 510 06-20-2025, 07:26 PM
Last Post: madscijr
  New drivers are good. James D Jarvis 0 373 04-30-2025, 12:42 PM
Last Post: James D Jarvis
  [split] Lines of Code bplus 20 3,126 01-25-2025, 05:11 PM
Last Post: Pete

Forum Jump:


Users browsing this thread: 1 Guest(s)