Comments (8)
Hi @chr15m
The following function helps me to get exit code, for stderr I guess that needs to create a tmp file...
but it, helps me a lot.
(defn sh! [command]
(let [cmd (str command "; echo «$?")
result (str-split (str-replace (sh* cmd) "\n" "¶") "«")]
(hash-map :out (str-replace (get result 0) "¶" "\n") :exit (get result 1))))
(def ls (sh! "ls -la"))
(println (get ls :out))
(println (get ls :exit))
(def err (sh! "laaaaa"))
(println (get err :out))
(println (get err :exit))
Thanks!
from flk.
Ugly as f**k but works
(defn sh! [command]
(let [uuid (str "/tmp/" (sh* "uuidgen"))
cmd (str command " 2> " uuid "; echo «$?")
result (str-split (str-replace (sh* cmd) "\n" "¶") "«")
err (sh* (str "cat " uuid))]
(sh* (str "rm " uuid))
(hash-map :out (str-replace (get result 0) "¶" "\n")
:err err
:exit (read-string (get result 1)))))
(println (sh! 'ping ["goober.com"]))
(def ls (sh! "ls -la"))
(println (get ls :out))
(println (get ls :err))
(println (get ls :exit))
(def err (sh! "laaaaa"))
(println (get err :out))
(println (get err :err))
(println (get err :exit))
I guess uuidgen
is default at ubuntu, a generic uuid can be used for safe files
https://github.com/dylanaraps/pure-bash-bible#generate-a-uuid-v4
escapes chars like ¶ and « should be changed to something better.
from flk.
This will probably require a bash level replacement for sh*
in extras.sh
because the existing implementation wraps the call in such a way that it's impossible to get at the return code.
from flk.
What I was thinking of is using the catch
function found here:
Just inlining that function into flk's bash functions and then writing a small wrapper to use it.
from flk.
This technique seems to work better:
PR coming through.
from flk.
Fixed on branch issue-12-sh-interop. @rosineygp please let me know if this solves your issue.
from flk.
Fixed on branch issue-12-sh-interop. @rosineygp please let me know if this solves your issue.
Works!!!
I just expected the return as hash-map... like clojure https://clojuredocs.org/clojure.java.shell/sh, but it's not a real problem.
The bash solution is ugliest of my code... but works better
Thanks @chr15m
I will try to implement last reverse and other small clojure functions if it works fine all will make a PR.
from flk.
Oh, that hash-map thing would be great.
from flk.
Related Issues (20)
- Makefile rule to create a sourceable version so that internals can be re-used. HOT 5
- Add tests for Fleck specific functions, re-using mal's test infrastructure.
- How do I get CLI args? HOT 1
- stdin doesnt read to EOF. only till end of first form HOT 2
- Piping examples/ip-addresses.clj into flk hangs
- Keyword as a function seems broken HOT 1
- Are you using Fleck? I would love to hear about it. HOT 1
- str-pos should return the position of string a in string b
- quasiquote symbol "`" break when it is merged in __FLECK__REPCAPTURE
- Help request serialize HOT 3
- What is the license? HOT 6
- env does not work on mac os HOT 15
- doc should say flk requires bash 4 or greater HOT 2
- range should be better supported HOT 1
- Carriage returns from sh* are incorrectly escaped HOT 1
- Makefile compilation mode failing [needs more info] HOT 13
- Some suggestions HOT 2
- Which versions of bash does this support? HOT 3
- Create and maintain a GitHub release instead of versioning the output file. HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from flk.