Re: [Factor-talk] command conundrum
Helpful suggestions! I'll work on them, and let you know what works for me. Thanks kindly, all ~cw On Mon, Oct 21, 2013 at 10:03 AM, John Benediktsson wrote: > These are all great suggestions, when you get it working, it would be > great if you'd contribute it! > > Best, > John. > > > On Mon, Oct 21, 2013 at 8:54 AM, Alex Vondrak wrote: > >> Maybe this whole thing is solved by going directly to the stream solution? >> >> $ rlwrap ./factor -run=listener 2> /dev/null >> IN: scratchpad USING: io.encodings.utf8 io.launcher ; >> IN: scratchpad "find /home/alex/talks/factor -name *.pdf" utf8 [ lines >> ] with-process-reader . >> { >> "/home/alex/talks/factor/factor.pdf" >> "/home/alex/talks/factor/factor-test.pdf" >> } >> IN: scratchpad "find /home/alex/talks/factor -name DOESNOTEXIST" utf8 >> [ lines ] with-process-reader . >> { } >> IN: scratchpad "find /proc -name PERMISSION_DENIED_ERROR" utf8 [ lines >> ] with-process-reader . >> Process exited with error code 1 >> >> Launch descriptor: >> >> T{ process >> { command >> "find /proc -name PERMISSION_DENIED_ERROR" >> } >> { environment H{ } } >> { environment-mode +append-environment+ } >> { stdout T{ fd { disposed t } { fd 19 } } } >> { group +same-group+ } >> { status 1 } >> { pipe >> T{ pipe >> { in T{ fd { disposed t } { fd 18 } } } >> { out T{ fd { disposed t } { fd 19 } } } >> } >> } >> } >> >> Type :help for debugging help. >> >> See >> - >> http://docs.factorcode.org/content/word-with-process-reader%2Cio.launcher.html >> - http://docs.factorcode.org/content/word-lines,io.html >> - General perusal of >> http://docs.factorcode.org/content/article-io.launcher.html and >> http://docs.factorcode.org/content/vocab-io.launcher.html >> >> As for the original problem of I/O redirection, there seem to be some >> docs on that at >> http://docs.factorcode.org/content/article-io.launcher.redirection.html >> and some examples in >> http://docs.factorcode.org/content/article-io.launcher.examples.html >> >> Hope that helps, >> --Alex Vondrak >> >> On Mon, Oct 21, 2013 at 2:26 AM, Björn Lindqvist >> wrote: >> > 2013/10/21 CW Alston : >> >> :: ( filename -- seq ) >> >> "'kMDItemFSName == " filename tri-quotes-surround append "'" >> >> append ; >> >> >> >> : ( filename -- process ) >> >> ! ( -- seq ) >> >> '[ "mdfind" , "-onlyin" , "/" , _ , ">" , >> >> "/Users/cwalston/factor/mdfind.txt" , ] >> >> { } make ! ( -- seq ) >> >>swap >>command >> >> t >>detached clone ! ( -- process ) >> >> ; >> >> >> >> And then, "Finding Joy in Combinators.pdf" contains a >> >> command >> >> sequence that looks like this: >> >> { >> >> "mdfind" >> >> "-onlyin" >> >> "/" >> >> "'kMDItemFSName == \"Finding Joy in Combinators.pdf\"'" >> >> ">" >> >> "/Users/cwalston/factor/mdfind.txt" >> >> } >> > >> > The command>> attribute in should be a string not a sequence >> > of strings. I think that is the core of your problem, not sure. Also, >> > input and output redirection is a feature of the shell, not the os, so >> > you need to wrap those commands in a subshell. But that is platform >> > dependent since not all shells are available everywhere and they dont >> > all have the same features. Here is how you could write a find utility >> > for Windows (using gnu find), maybe you can use it as a template: >> > >> > USING: formatting io.launcher kernel ; >> > IN: cmdpipe >> > >> > CONSTANT: find-bin "C:\\Program Files (x86)\\Git\\bin\\find.exe" >> > >> > : shell-command ( str -- str' ) >> > "cmd /C \"%s\"" sprintf ; >> > >> > : find-command ( dir pattern out-path -- str ) >> > [ find-bin ] 3dip "\"%s\" \"%s\" -name \"%s\" > \"%s\"" sprintf ; >> > >> > : run-find ( dir pattern out-path -- proc ) >> > find-command shell-command run-process ; >> > >> > IN: scratchpad "C:\\Users\\bjourne\\Downloads" "*.pdf" >> > "C:\\Users\\bjourne\\result.txt" run-find >> > >> > >> > -- >> > mvh/best regards Björn Lindqvist >> > >> > >> -- >> > October Webinars: Code for Performance >> > Free Intel webinars can help you accelerate application performance. >> > Explore tips for MPI, OpenMP, advanced profiling, and more. Get the >> most from >> > the latest Intel processors and coprocessors. See abstracts and >> register > >> > >> http://pubads.g.doubleclick.net/gampad/clk?id=60135031&iu=/4140/ostg.clktrk >> > ___ >> > Factor-talk mailing list >> > Factor-talk@lists.sourceforge.net >> > https://lists.sourceforge.net/lists/listinfo/factor-talk >> >> >> -- >> October Webinars: Code for Performance >> Free Intel webinars can help you accelerate application performance. >> Explore tips for MPI, OpenMP, advanced profiling, and more. Get the most >> from >>
Re: [Factor-talk] command conundrum
These are all great suggestions, when you get it working, it would be great if you'd contribute it! Best, John. On Mon, Oct 21, 2013 at 8:54 AM, Alex Vondrak wrote: > Maybe this whole thing is solved by going directly to the stream solution? > > $ rlwrap ./factor -run=listener 2> /dev/null > IN: scratchpad USING: io.encodings.utf8 io.launcher ; > IN: scratchpad "find /home/alex/talks/factor -name *.pdf" utf8 [ lines > ] with-process-reader . > { > "/home/alex/talks/factor/factor.pdf" > "/home/alex/talks/factor/factor-test.pdf" > } > IN: scratchpad "find /home/alex/talks/factor -name DOESNOTEXIST" utf8 > [ lines ] with-process-reader . > { } > IN: scratchpad "find /proc -name PERMISSION_DENIED_ERROR" utf8 [ lines > ] with-process-reader . > Process exited with error code 1 > > Launch descriptor: > > T{ process > { command > "find /proc -name PERMISSION_DENIED_ERROR" > } > { environment H{ } } > { environment-mode +append-environment+ } > { stdout T{ fd { disposed t } { fd 19 } } } > { group +same-group+ } > { status 1 } > { pipe > T{ pipe > { in T{ fd { disposed t } { fd 18 } } } > { out T{ fd { disposed t } { fd 19 } } } > } > } > } > > Type :help for debugging help. > > See > - > http://docs.factorcode.org/content/word-with-process-reader%2Cio.launcher.html > - http://docs.factorcode.org/content/word-lines,io.html > - General perusal of > http://docs.factorcode.org/content/article-io.launcher.html and > http://docs.factorcode.org/content/vocab-io.launcher.html > > As for the original problem of I/O redirection, there seem to be some > docs on that at > http://docs.factorcode.org/content/article-io.launcher.redirection.html > and some examples in > http://docs.factorcode.org/content/article-io.launcher.examples.html > > Hope that helps, > --Alex Vondrak > > On Mon, Oct 21, 2013 at 2:26 AM, Björn Lindqvist > wrote: > > 2013/10/21 CW Alston : > >> :: ( filename -- seq ) > >> "'kMDItemFSName == " filename tri-quotes-surround append "'" > >> append ; > >> > >> : ( filename -- process ) > >> ! ( -- seq ) > >> '[ "mdfind" , "-onlyin" , "/" , _ , ">" , > >> "/Users/cwalston/factor/mdfind.txt" , ] > >> { } make ! ( -- seq ) > >>swap >>command > >> t >>detached clone ! ( -- process ) > >> ; > >> > >> And then, "Finding Joy in Combinators.pdf" contains a > >> command > >> sequence that looks like this: > >> { > >> "mdfind" > >> "-onlyin" > >> "/" > >> "'kMDItemFSName == \"Finding Joy in Combinators.pdf\"'" > >> ">" > >> "/Users/cwalston/factor/mdfind.txt" > >> } > > > > The command>> attribute in should be a string not a sequence > > of strings. I think that is the core of your problem, not sure. Also, > > input and output redirection is a feature of the shell, not the os, so > > you need to wrap those commands in a subshell. But that is platform > > dependent since not all shells are available everywhere and they dont > > all have the same features. Here is how you could write a find utility > > for Windows (using gnu find), maybe you can use it as a template: > > > > USING: formatting io.launcher kernel ; > > IN: cmdpipe > > > > CONSTANT: find-bin "C:\\Program Files (x86)\\Git\\bin\\find.exe" > > > > : shell-command ( str -- str' ) > > "cmd /C \"%s\"" sprintf ; > > > > : find-command ( dir pattern out-path -- str ) > > [ find-bin ] 3dip "\"%s\" \"%s\" -name \"%s\" > \"%s\"" sprintf ; > > > > : run-find ( dir pattern out-path -- proc ) > > find-command shell-command run-process ; > > > > IN: scratchpad "C:\\Users\\bjourne\\Downloads" "*.pdf" > > "C:\\Users\\bjourne\\result.txt" run-find > > > > > > -- > > mvh/best regards Björn Lindqvist > > > > > -- > > October Webinars: Code for Performance > > Free Intel webinars can help you accelerate application performance. > > Explore tips for MPI, OpenMP, advanced profiling, and more. Get the most > from > > the latest Intel processors and coprocessors. See abstracts and register > > > > > http://pubads.g.doubleclick.net/gampad/clk?id=60135031&iu=/4140/ostg.clktrk > > ___ > > Factor-talk mailing list > > Factor-talk@lists.sourceforge.net > > https://lists.sourceforge.net/lists/listinfo/factor-talk > > > -- > October Webinars: Code for Performance > Free Intel webinars can help you accelerate application performance. > Explore tips for MPI, OpenMP, advanced profiling, and more. Get the most > from > the latest Intel processors and coprocessors. See abstracts and register > > http://pubads.g.doubleclick.net/gampad/clk?id=60135031&iu=/4140/ostg.clktrk > ___ > Factor-talk mailing list > Factor-talk@lists.sourceforge.net > https://lists.sourceforge.net/lists/list
Re: [Factor-talk] command conundrum
Maybe this whole thing is solved by going directly to the stream solution? $ rlwrap ./factor -run=listener 2> /dev/null IN: scratchpad USING: io.encodings.utf8 io.launcher ; IN: scratchpad "find /home/alex/talks/factor -name *.pdf" utf8 [ lines ] with-process-reader . { "/home/alex/talks/factor/factor.pdf" "/home/alex/talks/factor/factor-test.pdf" } IN: scratchpad "find /home/alex/talks/factor -name DOESNOTEXIST" utf8 [ lines ] with-process-reader . { } IN: scratchpad "find /proc -name PERMISSION_DENIED_ERROR" utf8 [ lines ] with-process-reader . Process exited with error code 1 Launch descriptor: T{ process { command "find /proc -name PERMISSION_DENIED_ERROR" } { environment H{ } } { environment-mode +append-environment+ } { stdout T{ fd { disposed t } { fd 19 } } } { group +same-group+ } { status 1 } { pipe T{ pipe { in T{ fd { disposed t } { fd 18 } } } { out T{ fd { disposed t } { fd 19 } } } } } } Type :help for debugging help. See - http://docs.factorcode.org/content/word-with-process-reader%2Cio.launcher.html - http://docs.factorcode.org/content/word-lines,io.html - General perusal of http://docs.factorcode.org/content/article-io.launcher.html and http://docs.factorcode.org/content/vocab-io.launcher.html As for the original problem of I/O redirection, there seem to be some docs on that at http://docs.factorcode.org/content/article-io.launcher.redirection.html and some examples in http://docs.factorcode.org/content/article-io.launcher.examples.html Hope that helps, --Alex Vondrak On Mon, Oct 21, 2013 at 2:26 AM, Björn Lindqvist wrote: > 2013/10/21 CW Alston : >> :: ( filename -- seq ) >> "'kMDItemFSName == " filename tri-quotes-surround append "'" >> append ; >> >> : ( filename -- process ) >> ! ( -- seq ) >> '[ "mdfind" , "-onlyin" , "/" , _ , ">" , >> "/Users/cwalston/factor/mdfind.txt" , ] >> { } make ! ( -- seq ) >>swap >>command >> t >>detached clone ! ( -- process ) >> ; >> >> And then, "Finding Joy in Combinators.pdf" contains a >> command >> sequence that looks like this: >> { >> "mdfind" >> "-onlyin" >> "/" >> "'kMDItemFSName == \"Finding Joy in Combinators.pdf\"'" >> ">" >> "/Users/cwalston/factor/mdfind.txt" >> } > > The command>> attribute in should be a string not a sequence > of strings. I think that is the core of your problem, not sure. Also, > input and output redirection is a feature of the shell, not the os, so > you need to wrap those commands in a subshell. But that is platform > dependent since not all shells are available everywhere and they dont > all have the same features. Here is how you could write a find utility > for Windows (using gnu find), maybe you can use it as a template: > > USING: formatting io.launcher kernel ; > IN: cmdpipe > > CONSTANT: find-bin "C:\\Program Files (x86)\\Git\\bin\\find.exe" > > : shell-command ( str -- str' ) > "cmd /C \"%s\"" sprintf ; > > : find-command ( dir pattern out-path -- str ) > [ find-bin ] 3dip "\"%s\" \"%s\" -name \"%s\" > \"%s\"" sprintf ; > > : run-find ( dir pattern out-path -- proc ) > find-command shell-command run-process ; > > IN: scratchpad "C:\\Users\\bjourne\\Downloads" "*.pdf" > "C:\\Users\\bjourne\\result.txt" run-find > > > -- > mvh/best regards Björn Lindqvist > > -- > October Webinars: Code for Performance > Free Intel webinars can help you accelerate application performance. > Explore tips for MPI, OpenMP, advanced profiling, and more. Get the most from > the latest Intel processors and coprocessors. See abstracts and register > > http://pubads.g.doubleclick.net/gampad/clk?id=60135031&iu=/4140/ostg.clktrk > ___ > Factor-talk mailing list > Factor-talk@lists.sourceforge.net > https://lists.sourceforge.net/lists/listinfo/factor-talk -- October Webinars: Code for Performance Free Intel webinars can help you accelerate application performance. Explore tips for MPI, OpenMP, advanced profiling, and more. Get the most from the latest Intel processors and coprocessors. See abstracts and register > http://pubads.g.doubleclick.net/gampad/clk?id=60135031&iu=/4140/ostg.clktrk ___ Factor-talk mailing list Factor-talk@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/factor-talk
Re: [Factor-talk] command conundrum
2013/10/21 CW Alston : > :: ( filename -- seq ) > "'kMDItemFSName == " filename tri-quotes-surround append "'" > append ; > > : ( filename -- process ) > ! ( -- seq ) > '[ "mdfind" , "-onlyin" , "/" , _ , ">" , > "/Users/cwalston/factor/mdfind.txt" , ] > { } make ! ( -- seq ) >swap >>command > t >>detached clone ! ( -- process ) > ; > > And then, "Finding Joy in Combinators.pdf" contains a > command > sequence that looks like this: > { > "mdfind" > "-onlyin" > "/" > "'kMDItemFSName == \"Finding Joy in Combinators.pdf\"'" > ">" > "/Users/cwalston/factor/mdfind.txt" > } The command>> attribute in should be a string not a sequence of strings. I think that is the core of your problem, not sure. Also, input and output redirection is a feature of the shell, not the os, so you need to wrap those commands in a subshell. But that is platform dependent since not all shells are available everywhere and they dont all have the same features. Here is how you could write a find utility for Windows (using gnu find), maybe you can use it as a template: USING: formatting io.launcher kernel ; IN: cmdpipe CONSTANT: find-bin "C:\\Program Files (x86)\\Git\\bin\\find.exe" : shell-command ( str -- str' ) "cmd /C \"%s\"" sprintf ; : find-command ( dir pattern out-path -- str ) [ find-bin ] 3dip "\"%s\" \"%s\" -name \"%s\" > \"%s\"" sprintf ; : run-find ( dir pattern out-path -- proc ) find-command shell-command run-process ; IN: scratchpad "C:\\Users\\bjourne\\Downloads" "*.pdf" "C:\\Users\\bjourne\\result.txt" run-find -- mvh/best regards Björn Lindqvist -- October Webinars: Code for Performance Free Intel webinars can help you accelerate application performance. Explore tips for MPI, OpenMP, advanced profiling, and more. Get the most from the latest Intel processors and coprocessors. See abstracts and register > http://pubads.g.doubleclick.net/gampad/clk?id=60135031&iu=/4140/ostg.clktrk ___ Factor-talk mailing list Factor-talk@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/factor-talk
Re: [Factor-talk] command conundrum
Erratum -- "the successful command-line phrase above" is: mdfind -onlyin / 'kMDItemFSName == "Finding Joy in Combinators.pdf"' > /Users/cwalston/factor/mdfind.txt ~CW Alston On Mon, Oct 21, 2013 at 12:49 AM, CW Alston wrote: > Greetings, folks - > > I'm trying to compose a find-file utility that takes advantage > of Spotlight's index on the Mac (I'm running 10.6.8). A simple search > tool built on find-file from io.directories.search works, even with > space-separated filenames, e.g., "Finding Joy in Combinators.pdf", but > it walks the entire hierarchy & I want to avoid that delay. > Here's that word, using locals: > > :: find-file* ( filename -- path/f ) ! REALLY LONG... CAN WE USE SPOTLIGHT? > filename :> this-filename > "/" t [ file-name this-filename = ] find-file > ; > > I found a command-line incantation that does the trick in Terminal: > > ➜ ~ git:(master) ✗ mdfind -onlyin / 'kMDItemFSName == "Finding Joy in > Combinators.pdf"' > > /Applications/Programming Languages/Functional Languages/Concatenative > languages/Joy (programming language) folder/Finding Joy in Combinators.pdf > ➜ ~ git:(master) ✗ > > I can successfully send the Terminal output to a file: > > ➜ ~ git:(master) ✗ mdfind -onlyin / 'kMDItemFSName == "Finding Joy in > Combinators.pdf"' > /Users/cwalston/factor/mdfind.txt > ➜ ~ git:(master) ✗ > > But I'm at loggerheads trying to compose a command that does the > same from > within Factor. My latest attempt is this: > > : tri-quotes-surround ( seq -- seq' ) """ """ surround ; ! goofy, > but seems to work > > :: ( filename -- seq ) > "'kMDItemFSName == " filename tri-quotes-surround append "'" > append ; > > : ( filename -- process ) > ! ( -- seq ) > '[ "mdfind" , "-onlyin" , "/" , _ , ">" , > "/Users/cwalston/factor/mdfind.txt" , ] > { } make ! ( -- seq ) >swap >>command > t >>detached clone ! ( -- process ) > ; > > And then, "Finding Joy in Combinators.pdf" contains a > command > sequence that looks like this: > { > "mdfind" > "-onlyin" > "/" > "'kMDItemFSName == \"Finding Joy in Combinators.pdf\"'" > ">" > "/Users/cwalston/factor/mdfind.txt" > } > > -which I thought translates to the successful command-line phrase above: > > mdfind -onlyin / 'kMDItemFSName == "Finding Joy in Combinators.pdf"' > > But it does't produce the desired result in my word that calls > : > > SYMBOL: file-process > SYMBOL: file-process-status > : mdfind-file ( filename -- seq ) ! Using Spotlight index > run-process > dup file-process set wait-for-process file-process-status set ! FOR > TESTING > "/Users/cwalston/factor/mdfind.txt" utf8 file-contents > ; > > e.g., > IN: scratchpad "Finding Joy in Combinators.pdf" mdfind-file > > --- Data stack: > "" > IN: scratchpad > > Meaning, nothing is written to /Users/cwalston/factor/mdfind.txt ! > Ideally, I'd rather stream the result directly to Factor, but I can't > figure that out > until I get the command straight. > > Any insights welcome! Thanks, > ~Charles Alston > > -- > *~ Memento Amori* > -- *~ Memento Amori* -- October Webinars: Code for Performance Free Intel webinars can help you accelerate application performance. Explore tips for MPI, OpenMP, advanced profiling, and more. Get the most from the latest Intel processors and coprocessors. See abstracts and register > http://pubads.g.doubleclick.net/gampad/clk?id=60135031&iu=/4140/ostg.clktrk___ Factor-talk mailing list Factor-talk@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/factor-talk
[Factor-talk] command conundrum
Greetings, folks - I'm trying to compose a find-file utility that takes advantage of Spotlight's index on the Mac (I'm running 10.6.8). A simple search tool built on find-file from io.directories.search works, even with space-separated filenames, e.g., "Finding Joy in Combinators.pdf", but it walks the entire hierarchy & I want to avoid that delay. Here's that word, using locals: :: find-file* ( filename -- path/f ) ! REALLY LONG... CAN WE USE SPOTLIGHT? filename :> this-filename "/" t [ file-name this-filename = ] find-file ; I found a command-line incantation that does the trick in Terminal: ➜ ~ git:(master) ✗ mdfind -onlyin / 'kMDItemFSName == "Finding Joy in Combinators.pdf"' /Applications/Programming Languages/Functional Languages/Concatenative languages/Joy (programming language) folder/Finding Joy in Combinators.pdf ➜ ~ git:(master) ✗ I can successfully send the Terminal output to a file: ➜ ~ git:(master) ✗ mdfind -onlyin / 'kMDItemFSName == "Finding Joy in Combinators.pdf"' > /Users/cwalston/factor/mdfind.txt ➜ ~ git:(master) ✗ But I'm at loggerheads trying to compose a command that does the same from within Factor. My latest attempt is this: : tri-quotes-surround ( seq -- seq' ) """ """ surround ; ! goofy, but seems to work :: ( filename -- seq ) "'kMDItemFSName == " filename tri-quotes-surround append "'" append ; : ( filename -- process ) ! ( -- seq ) '[ "mdfind" , "-onlyin" , "/" , _ , ">" , "/Users/cwalston/factor/mdfind.txt" , ] { } make ! ( -- seq ) swap >>command t >>detached clone ! ( -- process ) ; And then, "Finding Joy in Combinators.pdf" contains a command sequence that looks like this: { "mdfind" "-onlyin" "/" "'kMDItemFSName == \"Finding Joy in Combinators.pdf\"'" ">" "/Users/cwalston/factor/mdfind.txt" } -which I thought translates to the successful command-line phrase above: mdfind -onlyin / 'kMDItemFSName == "Finding Joy in Combinators.pdf"' But it does't produce the desired result in my word that calls : SYMBOL: file-process SYMBOL: file-process-status : mdfind-file ( filename -- seq ) ! Using Spotlight index run-process dup file-process set wait-for-process file-process-status set ! FOR TESTING "/Users/cwalston/factor/mdfind.txt" utf8 file-contents ; e.g., IN: scratchpad "Finding Joy in Combinators.pdf" mdfind-file --- Data stack: "" IN: scratchpad Meaning, nothing is written to /Users/cwalston/factor/mdfind.txt ! Ideally, I'd rather stream the result directly to Factor, but I can't figure that out until I get the command straight. Any insights welcome! Thanks, ~Charles Alston -- *~ Memento Amori* -- October Webinars: Code for Performance Free Intel webinars can help you accelerate application performance. Explore tips for MPI, OpenMP, advanced profiling, and more. Get the most from the latest Intel processors and coprocessors. See abstracts and register > http://pubads.g.doubleclick.net/gampad/clk?id=60135031&iu=/4140/ostg.clktrk___ Factor-talk mailing list Factor-talk@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/factor-talk