]> woffs.de Git - fd/haskell-amqp-utils.git/commitdiff
stdin handling without using /dev/stdin
authorFrank Doepper <[email protected]>
Tue, 5 Nov 2019 16:44:24 +0000 (17:44 +0100)
committerFrank Doepper <[email protected]>
Tue, 5 Nov 2019 16:44:24 +0000 (17:44 +0100)
Network/AMQP/Utils/Options.hs
agitprop.hs
plane.hs

index e3d4a01f02f3900a8deae4eeebe1bf0e51e37a43..463b16ffbf0a0fa3e688c9258d6ce6e107bc5c87 100644 (file)
@@ -81,7 +81,7 @@ instance Default Args where
       []
       Nothing
       ""
-      "/dev/stdin"
+      "-"
       "/dev/stdout"
       False
       False
index 4e37b479d9c69d3a8c1e5fa8cd63b6527cd58464..fe05b81fca2be4226f985ec254edba5186144e2c 100644 (file)
@@ -33,7 +33,10 @@ main = do
   printparam' "client version" $ "amqp-utils " ++ (showVersion version)
   printparam' "routing key" $ rKey args
   printparam' "exchange" $ currentExchange args
-  isDir <- F.getFileStatus (inputFile args) >>= return . F.isDirectory
+  isDir <-
+    if inputFile args == "-"
+      then return False
+      else F.getFileStatus (inputFile args) >>= return . F.isDirectory
   if isDir
     then printparam' "hotfolder" $ inputFile args
     else printparam' "input file" $
@@ -70,7 +73,10 @@ main = do
          hr $ "END watching " ++ (inputFile args)
        else do
          hr $ "BEGIN sending"
-         messageFile <- BL.readFile (inputFile args)
+         messageFile <-
+           if inputFile args == "-"
+             then BL.getContents
+             else BL.readFile (inputFile args)
          if (lineMode args)
            then mapM_ (publishOneMsg Nothing) (BL.lines messageFile)
            else publishOneMsg (Just (inputFile args)) messageFile
index 44dc9114e9ce06e9612089e8f36f8fe8037bff98..db6b52cbbdcc017223ac80c0b984b58b98732ffb 100644 (file)
--- a/plane.hs
+++ b/plane.hs
@@ -37,7 +37,10 @@ main = do
       bindQueue chan q (T.pack $ currentExchange args) q
     else return ()
   printparam' "input file" $ inputFile args
-  message <- BL.readFile (inputFile args)
+  message <-
+    if inputFile args == "-"
+      then BL.getContents
+      else BL.readFile (inputFile args)
   printparam' "output file" $ outputFile args
   h <- openBinaryFile (outputFile args) WriteMode
   ctag <- consumeMsgs chan q NoAck (rpcClientCallback h tid args)