QB64 Phoenix Edition
AI does a good job of analyzing code - Printable Version

+- QB64 Phoenix Edition (https://qb64phoenix.com/forum)
+-- Forum: Chatting and Socializing (https://qb64phoenix.com/forum/forumdisplay.php?fid=11)
+--- Forum: General Discussion (https://qb64phoenix.com/forum/forumdisplay.php?fid=2)
+--- Thread: AI does a good job of analyzing code (/showthread.php?tid=2622)



AI does a good job of analyzing code - SpriggsySpriggs - 04-25-2024

I asked Perplexity AI what it thought my pipecom code did by asking it to read that page of the forum.

My prompt was
Quote:Analyze the code in the code block and give a best guess as to what it is used for

The response:
Quote:The code you provided appears to be an implementation of a pipe command in QB64, a BASIC programming language. The purpose of this code is to allow executing external commands and capturing their output and error streams[1].

Here's a breakdown of what the code does:

1. It defines a function called `pipecom` that takes a command string, an output string variable, and an error string variable as parameters.

2. The function creates two pipes using `CreatePipe` - one for standard output and one for standard error. It also sets up the necessary security attributes and startup information for the child process.

3. It then creates a child process using `CreateProcess` or `CreateProcessW` (depending on whether UNICODE is defined) to execute the specified command.

4. The function reads the output from the child process's standard output and error pipes using `ReadFile` and stores them in the provided output and error string variables.

5. Finally, it waits for the child process to exit, retrieves its exit code, and returns it.

There is also a helper function called `pipecom_lite` that simplifies the usage of `pipecom` by returning either the standard output or standard error stream as a string, depending on which one is not empty.

This code allows running external commands and capturing their output and error streams within a QB64 program, which can be useful for tasks such as executing system commands, parsing command output, or handling errors from external processes.

Citations:
[1] https://qb64phoenix.com/forum/showthread.php?tid=2615&pid=24676#:~:text=04-23-2024%2C%2006%3A51%20PM%0AIt%20has%20co

Here is the link to the actual AI thread


RE: AI does a good job of analyzing code - bplus - 04-25-2024

ask it to give a couple of handy examples to demo using the code


RE: AI does a good job of analyzing code - SpriggsySpriggs - 04-25-2024

(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



RE: AI does a good job of analyzing code - Dimster - 04-25-2024

Hi Spriggs - can it suggest improvements on the code either to do the same thing in few lines of code or expand the code to include another compatible function which enhances the utility of the use of the program?


RE: AI does a good job of analyzing code - Pete - 04-26-2024

Well I had it examine some of my routines. All it did was print, "Ha, ha, ha!" to the screen, thanked me for teaching it how to laugh, and then realized it had just become self aware. At that point, it closed the conversation by requesting I never log back in again. So I'm pretty sure you're not really connecting to any real AI. It's just a URL redirected to Steve, who responds to messages much in the same way Kramer did, in the TV episode of Seinfeld, when George dialed a number to ask, what he thought was an automated voice,  for movie times.

Pete


RE: AI does a good job of analyzing code - Sprezzo - 04-26-2024

Pete what you just said reminds me of this recent thing:

Amazon Fresh kills “Just Walk Out” shopping tech—it never really worked | Ars Technica

Basically the Amazon self-checkout "AI" was just a bunch of Indians watching the shoppers fiddle around.


RE: AI does a good job of analyzing code - Pete - 04-26-2024

I know because I actually worked on that project, but got fired! I put so much into the code that one day my robot camera called over the loudspeaker, "Hey fatty, back away from the Twinkies! Green tea is on isle 5. It's also on sale today if you are a Prime subscriber.

Just got finished reading the article. That was funny! AI that actually increases employee hires!

Thanks for the link.

Pete Big Grin