Author Topic: Question about using SHELL "dir" on non windows OS.  (Read 8959 times)

0 Members and 1 Guest are viewing this topic.

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: Question about using SHELL "dir" on non windows OS.
« Reply #30 on: February 05, 2021, 11:08:57 pm »
I'll be using direntry, but I wanted to get this method figured out.  One of my quirks I guess, can't let things go very easy while they're still gnawing on me.

- Dav

Yeah, I know that.

But I'm saying don't worry what Linux does about temp files, you would be switching to the other method by then I would think.

Offline SpriggsySpriggs

  • Forum Resident
  • Posts: 1145
  • Larger than life
    • View Profile
    • GitHub
Re: Question about using SHELL "dir" on non windows OS.
« Reply #31 on: February 05, 2021, 11:10:58 pm »
Might I suggest using pipecom to get rid of using temp files? There will be a speed increase and will work on all platforms still
Shuwatch!

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: Question about using SHELL "dir" on non windows OS.
« Reply #32 on: February 05, 2021, 11:16:19 pm »
Oh man I just remembered an advantage with temp files, you can get all kinds of details about the files too and might be easier to do pathed-file-spec.

@SpriggsySpriggs  I have that pipecom code of yours, offhand I don't remember if it can do all the details like a Command prompt Dir with all the switches can do. What do you say?


Offline SpriggsySpriggs

  • Forum Resident
  • Posts: 1145
  • Larger than life
    • View Profile
    • GitHub
Re: Question about using SHELL "dir" on non windows OS.
« Reply #33 on: February 05, 2021, 11:19:43 pm »
@bplus It will do any command. It simply returns console output. Anything you want. It can replace any SHELL. Its main advantage is speed and immediate filling of a variable rather than writing to a file, opening it, reading it, closing it, deleting it.
« Last Edit: February 05, 2021, 11:23:55 pm by SpriggsySpriggs »
Shuwatch!

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: Question about using SHELL "dir" on non windows OS.
« Reply #34 on: February 05, 2021, 11:22:28 pm »
Well I will check it out again, do you happen to have a link?

Offline SpriggsySpriggs

  • Forum Resident
  • Posts: 1145
  • Larger than life
    • View Profile
    • GitHub
Re: Question about using SHELL "dir" on non windows OS.
« Reply #35 on: February 05, 2021, 11:25:43 pm »
@bplus Click my link in my signature for my API Collection, click the GitHub link on that page and then navigate to the Cross Platform folder. It's in there.
Shuwatch!

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: Question about using SHELL "dir" on non windows OS.
« Reply #36 on: February 06, 2021, 12:39:03 am »
@Dav  have you seen Doppler's method?

Code: QB64: [Select]
  1.  
  2. Shell "dir /b *.* | clip"
  3.  
  4.  
  5.  

0 temp files!!!

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: Question about using SHELL "dir" on non windows OS.
« Reply #37 on: February 06, 2021, 12:42:40 am »
OK @SpriggsySpriggs

I found this that requires much less digging:
https://www.qb64.org/forum/index.php?topic=3167.msg124332#msg124332

Code: QB64: [Select]
  1. _Title "Dir replacement " ' >>>>>>>>>>>>>> needs pipecom.h in QB64 folder
  2. 'spriggsySpriggs ref:  https://www.qb64.org/forum/index.php?topic=3167.msg124332#msg124332
  3.  
  4. ' the following is the pipecom.h file without comments
  5.  
  6. 'const char* pipecom (char* cmd){
  7. 'string data;
  8. 'FILE * stream;
  9. 'const int max_buffer = 256;
  10. 'char buffer[max_buffer];
  11.  
  12. '    stream = popen(cmd, "r");
  13. '    if (stream) {
  14. '        while (!feof(stream)) {
  15. '            if (fgets(buffer, max_buffer, stream) != NULL) {
  16. '                data.append(buffer);
  17. '            }
  18. '        }
  19. '        pclose(stream);
  20. '    }
  21. '    //
  22. '    //cout << data;
  23. '    const char* dataout;
  24. '    dataout = strdup(data.c_str());
  25. '    return dataout;
  26. '}
  27.  
  28.  
  29.  
  30. Declare Library "pipecom"
  31.     Function pipecom$ (cmd As String)
  32.  
  33.  
  34. ' NOTE: these slants work \    these do not /
  35. 'F = pipecom("dir C:/*.*") ' Linux needs other switches
  36. F = pipecom("dir /b *.BAS") 'if you need just the filenames and not the rest of the output
  37.  
  38.  

Offline Dav

  • Forum Resident
  • Posts: 792
    • View Profile
Re: Question about using SHELL "dir" on non windows OS.
« Reply #38 on: February 06, 2021, 09:52:02 am »
Oh cool. I see I had that pipcom downloaded already, forgot about it.  Nice one.

Really slick trick, doppler's method.

- Dav

Offline SpriggsySpriggs

  • Forum Resident
  • Posts: 1145
  • Larger than life
    • View Profile
    • GitHub
Re: Question about using SHELL "dir" on non windows OS.
« Reply #39 on: February 06, 2021, 10:18:44 am »
@Dav the main thing though is that using clip slows down shell execution by quite a bit. At that point you should use temp files because that's quicker than clip.
Shuwatch!

Offline Dav

  • Forum Resident
  • Posts: 792
    • View Profile
Re: Question about using SHELL "dir" on non windows OS.
« Reply #40 on: February 06, 2021, 11:42:06 am »
Yes, good point. @SpriggsySpriggs.

- Dav

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: Question about using SHELL "dir" on non windows OS.
« Reply #41 on: February 06, 2021, 01:27:11 pm »
Can't be that great a difference reading/writing files to disk is slower than access to Clips stored in RAM, I would think.

Offline SpriggsySpriggs

  • Forum Resident
  • Posts: 1145
  • Larger than life
    • View Profile
    • GitHub
Re: Question about using SHELL "dir" on non windows OS.
« Reply #42 on: February 06, 2021, 01:29:38 pm »
@bplus I'm talking about using clip. When you pipe to clip it takes a lot longer than just writing to a file. The clipboard itself isn't slow. It's the usage of clip that is.
Shuwatch!

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: Question about using SHELL "dir" on non windows OS.
« Reply #43 on: February 06, 2021, 01:39:25 pm »
Are you saying you can't get access to clip data faster than you can get access file data?
Is clip data written to temp files on disk by OS, that would be an explanation about access being slower for clip but seems not very smart coding. Send Steve over and show them how to use memory ;-))


Quote
It's the usage of clip that is.
The usage of the data is up to us in our QB64 code.

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: Question about using SHELL "dir" on non windows OS.
« Reply #44 on: February 06, 2021, 01:54:19 pm »
Oh it's probably the SHELL that's slower than pipecom.