Author Topic: Opinion, insite, idea's wanted for shell out pass back through the clipboard  (Read 4162 times)

0 Members and 1 Guest are viewing this topic.

Offline doppler

  • Forum Regular
  • Posts: 241
    • View Profile
Basically I am looking for a better way to pass back clipboard content from a shell out.

Start with: "shell "dir *.* | clip", not what I am going to do.  But you get the idea.  What comes back is line by line content in the clipboard where the lines are separated  by (cr/lf).   ie:line1(cr/lf)line2(cr/lf),line3(cr/lf)....

I can only think of "a$=_clipboard$" then using instr a$ taking the lines content with mid$'s.  Tedious and time consuming.  An alternate way would be shell "dir *.* > somefile.txt" and reading the file back with line inputs.  Also time consuming.

All input and out devices are considered block devices on windows.  Some are read only (keyboard), some are r/w (display).  The clip board is no different to windows.  And its a block device that is r/w.  The open command does not support many block devices in QB64.  So the question is the clipboard a "open-able" device on windows.  And how to do it?  I happen to be using the alternate way now.



Offline SpriggsySpriggs

  • Forum Resident
  • Posts: 1145
  • Larger than life
    • View Profile
    • GitHub
I'd say if you aren't wanting to split everything up line by line or read in contents (which I think is quite quick in most scenarios I've dealt with) then you should look at this:
https://docs.microsoft.com/en-us/windows/win32/dataxchg/clipboard-functions

I can't guarantee that this will work for you. I haven't looked at this portion of the WinAPI yet.
Shuwatch!

Offline doppler

  • Forum Regular
  • Posts: 241
    • View Profile
Yea, I saw that on google search results.  Using the windows api's are not the easiest things to do inside qb64.  I played a long time ago the string method, it was very slow and complex.  That's why I went with file re-direction method.  A really long time ago, when qb45 was still king.  I saw and used a way to take clipboard content and directly pump it in to an array using pointers and such.  This is not the dos age anymore.  So that nice way is gone now.  Unless memory arrays can be directly adjusted in QB64 ????

« Last Edit: October 06, 2020, 02:59:40 pm by doppler »

Offline SpriggsySpriggs

  • Forum Resident
  • Posts: 1145
  • Larger than life
    • View Profile
    • GitHub
Using the windows api's are not the easiest things to do inside qb64.

Trust me, they're not as hard as you think. I'll try messing with it myself here and reply with source code if it is successful.
Shuwatch!

Offline Pete

  • Forum Resident
  • Posts: 2361
  • Cuz I sez so, varmint!
    • View Profile
I don't think I understand the question. Your piping example works.

If I use... SHELL "dir /b C:\tmp-copy-qb64bas\*.wav | clip": PRINT _CLIPBOARD$

Results:
----------------------------------
recording.wav

test1.wav
----------------------------------

The same results would be given if I sent the results to a file...  "dir /b C:\tmp-copy-qb64bas\*.wav>junk.txt"

If I want to remove the print characters like carriage return, I think the only way to do so is to parse them out where a$ = _clipboard$ and then parse a$.

Code: QB64: [Select]
  1. OPEN "junk.txt" FOR BINARY AS #1
  2. a$ = SPACE$(LOF(1))
  3. GET #1, 1, a$
  4.  
  5. DO WHILE INSTR(a$, CHR$(13) + CHR$(10))
  6.     a$ = MID$(a$, 1, INSTR(a$, CHR$(13) + CHR$(10)) - 1) + MID$(a$, INSTR(a$, CHR$(13) + CHR$(10)) + 2)
  7.  
  8.  

or...

Code: QB64: [Select]
  1. SHELL "dir /b C:\tmp-copy-qb64bas\*.htm* | clip"
  2.  
  3. DO WHILE INSTR(a$, CHR$(13) + CHR$(10))
  4.     a$ = MID$(a$, 1, INSTR(a$, CHR$(13) + CHR$(10)) - 1) + MID$(a$, INSTR(a$, CHR$(13) + CHR$(10)) + 2)

Results for either:

----------------------------------
recording.wavtest1.wav
----------------------------------

Is that your intended results?

Pete
« Last Edit: October 06, 2020, 02:40:20 pm by Pete »
Want to learn how to write code on cave walls? https://www.tapatalk.com/groups/qbasic/qbasic-f1/

Offline doppler

  • Forum Regular
  • Posts: 241
    • View Profile
My original idea is I need a list of files quickly from a directory passed back to my qb64 program.  Output re-direction is messy and leaves behind file(s) that need to be cleaned up later.  I thought the clipboard being ram would be faster than opening a list from a re-directed output.  The clipboard leads to special handling of a string to parse out the needed content.  If the clipboard was an open-able device I could use an "line input" to take the lines out of the clipboard one by one since (cr/lf) is the delimiter for line input.

I am just thinking about a more elegant way of doing it.  Doing the mid$ thing seems clunky (maybe the only real way).  I know the piping works, I was looking for a "elegant,generic" way of getting the data.

Offline jack

  • Seasoned Forum Regular
  • Posts: 408
    • View Profile
how about using the WinAPI FindFirstFile, FindNextFile and FindClose ? https://stackoverflow.com/questions/612097/how-can-i-get-the-list-of-files-in-a-directory-using-c-or-c

Offline doppler

  • Forum Regular
  • Posts: 241
    • View Profile
WinAPI FindFirstFile, FindNextFile and FindClose
I thought of that one.  Since there is a program here already:
Code: QB64: [Select]
  1.     FUNCTION load_dir& (s AS STRING)
  2.     FUNCTION has_next_entry& ()
  3.     SUB close_dir ()
  4.     SUB get_next_entry (s AS STRING, flags AS LONG, file_size AS LONG)
  5.  
  6. REDIM Dir(0) AS STRING, File(0) AS STRING
  7.  
  8. 'D$ = _CWD$
  9. D$ = "D:\mangadex"
  10. GetFileList D$, Dir(), File()
  11.  
  12. PRINT "SUBDIRECTORIES"; UBOUND(dir)
  13. FOR i = 1 TO UBOUND(dir)
  14.     PRINT Dir(i),
  15.  
  16. PRINT "FILES"; UBOUND(file): PRINT: PRINT
  17. FOR i = 1 TO UBOUND(file)
  18.     PRINT File(i),
  19.  
  20. SUB GetFileList (SearchDirectory AS STRING, DirList() AS STRING, FileList() AS STRING)
  21.     CONST IS_DIR = 1
  22.     CONST IS_FILE = 2
  23.     DIM flags AS LONG, file_size AS LONG
  24.  
  25.     REDIM _PRESERVE DirList(100), FileList(100)
  26.     DirCount = 0: FileCount = 0
  27.  
  28.     IF load_dir(SearchDirectory) THEN
  29.         DO
  30.             length = has_next_entry
  31.             IF length > -1 THEN
  32.                 nam$ = SPACE$(length)
  33.                 get_next_entry nam$, flags, file_size
  34.                 IF (flags AND IS_DIR) OR _DIREXISTS(SearchDirectory + nam$) THEN
  35.                     DirCount = DirCount + 1
  36.                     IF DirCount > UBOUND(DirList) THEN REDIM _PRESERVE DirList(UBOUND(DirList) + 100)
  37.                     DirList(DirCount) = nam$
  38.                 ELSEIF (flags AND IS_FILE) OR _FILEEXISTS(SearchDirectory + nam$) THEN
  39.                     FileCount = FileCount + 1
  40.                     IF FileCount > UBOUND(filelist) THEN REDIM _PRESERVE FileList(UBOUND(filelist) + 100)
  41.                     FileList(FileCount) = nam$
  42.                 END IF
  43.             END IF
  44.         LOOP UNTIL length = -1
  45.         close_dir
  46.     ELSE
  47.     END IF
  48.     REDIM _PRESERVE DirList(DirCount)
  49.     REDIM _PRESERVE FileList(FileCount)
  50.  
  51.  

But redirect and read back would be faster.

Offline SpriggsySpriggs

  • Forum Resident
  • Posts: 1145
  • Larger than life
    • View Profile
    • GitHub
Doppler, I'm away from home right now but I've got the clipboard API almost done being written. Also, for the FindNextFile, there is a post from 2018, I think, that does what Pete mentioned. I downloaded the code and was going to put it in my API collection (with credit, of course).
Shuwatch!