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

Question: passing code via pipe? #520

Closed
amilajack opened this issue Oct 2, 2016 · 7 comments
Closed

Question: passing code via pipe? #520

amilajack opened this issue Oct 2, 2016 · 7 comments

Comments

@amilajack
Copy link

I'm using the following code to pass javascript source code (as a string) as stdout to anther command.

exec(`echo "${jsCodeHere}" | someOtherCommand`)

The issue with this is there are a bunch of issues caused by the syntax of javascript being evaluated by bash. Is there a better way of doing this?

@nfischer
Copy link
Member

nfischer commented Oct 2, 2016

Did you look into our support for pipes? The built-in echo should treat text normally, and then you can pipe it via echo(code).exec(cmd). Let me know if this helps!

You can also use the ShellString constructor and it'll be like echo, except it won't print to stdout.

@amilajack
Copy link
Author

This worked perfectly! Thanks!

@amilajack amilajack reopened this Oct 2, 2016
@amilajack
Copy link
Author

It seems like echo(code).exec(cmd) doesn't support the { silent: true } option. Does it?

@nfischer
Copy link
Member

nfischer commented Oct 2, 2016

Exec should. Echo does not support it yet (but I can add support)

@amilajack
Copy link
Author

So adding support will suppress the output but still pass it to exec?

@nfischer
Copy link
Member

nfischer commented Oct 2, 2016

For now, the recommended workaround is (new shell.ShellString("text you don't want to print to the console")).exec(cmd).

But I'll probably write something up that's more intuitive, since we get this issue a lot. If that works for you, feel free to close this issue (we have some other issues related to this, see #146 and #501).

@nfischer nfischer closed this as completed Oct 2, 2016
@ariporad
Copy link
Contributor

ariporad commented Oct 2, 2016

@nfischer: Suggestion (and I'm happy to open a PR for this): we could make a shell.pipe(str) method, that does this:

shell.pipe = function (str) {
    return new shell.ShellString(str);
}

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

3 participants