Skip to content
This repository has been archived by the owner on Apr 24, 2018. It is now read-only.

envoy doesn't support '>>', '<<' symbols in shell command. #19

Closed
kracekumar opened this issue Jan 31, 2012 · 12 comments
Closed

envoy doesn't support '>>', '<<' symbols in shell command. #19

kracekumar opened this issue Jan 31, 2012 · 12 comments

Comments

@kracekumar
Copy link
Contributor

In [24]: n = envoy.run("cat requirements.txt >> py.txt")

In [25]: n.std_err
Out[25]: 'cat: >>: No such file or directory\ncat: py.txt: No such file or directory\n'

@kennethreitz
Copy link
Contributor

Correct. :)

@kracekumar
Copy link
Contributor Author

so how to proceed ?

@amoffat
Copy link

amoffat commented Feb 4, 2012

+1, this would be useful

@kracekumar
Copy link
Contributor Author

Yes, let me crush my grey matter not now, after three days :)

Thanks & Regards

"Talk is cheap, show me the code" -- Linus Torvalds
kracekumar
www.kracekumar.com
*

@kennethreitz
Copy link
Contributor

I'm torn on this. I'm not sure how this would be very useful programmatically.

@kracekumar
Copy link
Contributor Author

Since envoy is alternate to subprocess people tend to think envoy.run("let us shoot the command here"), since subprocess works fine with >> << people expect to try all sorts in envoy. We can parse the command and in case any one if them is present >,<,>>,<<, we will achieve the desired result using with and open if it is a file. I am not 100%sure this will work.

envoy rocks

if command is cat read.txt > write.txt

In [9]: with open('read.txt', 'r') as f:
    with open('write.txt', 'w') as w:
        w.writelines(f)
   ...:         

In [10]: cat write.txt
envoy rocks```

@amoffat
Copy link

amoffat commented Feb 5, 2012

Programmatically, it's about as easy to redirect as it is to compose an initial function:

envoy.run("cat %s" % f1)
envoy.run("cat %s >> %s" % (f1,f2))

Granted "cat" is a bit contrived...the redirection does still save the extra keystrokes of opening a file with the appropriate mode, grabbing the stdout/stderr, and writing.

with open(f2, "a") as h: h.write(envoy.run("cat f1").std_out)

vs

envoy.run("cat f1 >> %s" % f2)

It feels more natural to use redirection in the command string. It would also seem consistent with the current API since piping is there.

Thoughts?

@kracekumar
Copy link
Contributor Author

@amoffat : seems much better than the one i suggested. We can still think on it.

@aljosa
Copy link

aljosa commented Apr 16, 2012

how about performance and compatibility?
i've run into this issue when i tried to do a pg_dump w/ envoy.run(), i know that "pg_dump ... > file.sql" works w/o problems for extremely large files.

will something like "with open(...) as h: h.write(envoy.run("pg_dump ...").std_out)" also work w/o problems?

@kracekumar
Copy link
Contributor Author

examples

  1. nohup python test.py >> test.out &
  2. command | tee pipe.py

We might need to write own grammar, i feel pbs should be handly when compared to envoy, @kennethreitz what you say ?

@xiongchiamiov
Copy link

Just ran into this. :/

Parsing shell commands is a tricky business, with a lot of subtle traps. But that's why I want a library to do it for me. ;)

@kennethreitz
Copy link
Contributor

This project is in a bit of a crisis state — it's really useful, and I use it on a daily basis. However, I wrote it in a few afternoons several years ago and haven't touched it since. In order to get the project into a stable state I'm closing all issues and pull requests

Don't take this as aggressive — it's just necessary for the project to make any progress any time soon (it's pretty clear the project is effectively unmaintained at the moment). Great things to come! Please watch the GitHub logs and feel free to re-open this discussion soon. I just need to really it into a good state first.

✨ ❤️ ✨

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

No branches or pull requests

5 participants