Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

More effecient piping with large data #86

Open
codygman opened this issue Jan 31, 2015 · 1 comment
Open

More effecient piping with large data #86

codygman opened this issue Jan 31, 2015 · 1 comment

Comments

@codygman
Copy link

Having an issue with figuring out how to use handles. Also wanted to verify handles are the correct solution rather than say runFoldLines or the other alternative I can't recall at the moment.

Surely examples of how to do the two snippets below in Shelly would be useful to many people:

zcat large.mysql.gz | mysql largedb
cat bigfile | grep things

I guess those two are pretty much the same, though I think runFoldLines might be a better alternative for the second.

{-# LANGUAGE ExtendedDefaultRules #-}
{-# LANGUAGE OverloadedStrings    #-}
{-# OPTIONS_GHC -fno-warn-type-defaults #-}
import           Data.Monoid
import           Data.Text   as T
import           Shelly
default (T.Text)

main = shelly $ do
  -- I'm trying to do "zcat large.mysql.gz | mysql largedb" basically
  -- minimal reproduction:
  run "echo" ["a very large file"] -|- run_ "grep" ["file"] -- predictably runs out of memory
  -- runHandle "echo" ["test"] $ \h -> run "grep" ["test"] -- thought this was the equivalent
@gregwebs
Copy link
Owner

The easiest way to run these right now is to just let the shell do it. Something like the following (untested).

shelly $ escaping False
  run "sh" ["-c", "zcat large.mysql.gz | mysql largedb"]

There is no magic going on with the handles. It is just a low level interface. If you want to create a connection through handles you would need to use runHandles and use the handle from the first command as an input handle. Perhaps you can post some example code that does this and we can make some conveniences for it?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants