Giter VIP home page Giter VIP logo

command's Introduction

command

is a fork of the [shell] external from Günter Geiger's ggee library.

It provides a way to execute commands from Pd. Its goal is to give more fine-grained control over the process it manages. Unlike the original [shell] external, [command] executes commands directly and does not wrap them into a shell. This means shell features cannot be used with [command]. However, they can be used in shell scripts that can be executed with [command].

Features

  • runs asynchronously (without blocking Pd)
  • kill method for sending SIGINT to currently running command.
  • send method for sending data to STDIN of currently running command.
  • env method for setting environment variables.
  • separate outlet for STDERR of command.
  • reports exit code on left-most outlet.
  • uses dedicated method exec for command execution to avoid conflicts between command and method names.
  • searches relative to patch instead of relative to Pd when calling commands with relative path. This makes projects using custom scripts or binaries more portable.
  • -b flag for binary output. This can be used to bypass FUDI parsing. Useful for cases when characters like leading or trailing spaces should be kept.
  • -s flag for synchronous mode. When enabled, command execution blocks Pd while maintaining depth-first order.

Authors

2002 - 2006 Guenter Geiger [email protected]
2005 - 2010 Hans-Christoph Steiner [email protected]
2008 - 2022 IOhannes m zmölnig [email protected]
2019 jyg [email protected]
2021 - 2022 Roman Haefeli [email protected]

License

Tcl/Tk License. Refer to LICENSE.txt

command's People

Contributors

katjav avatar reduzent avatar umlaeute avatar danomatika avatar

Stargazers

brunorohde avatar Max Neupert avatar

Watchers

 avatar  avatar Raphael Isdant avatar

command's Issues

add a -b flag for binary output

In order to cover cases where the exact output needs to be preserved without FUDI parsing, a binary output would be helpful.

regression: 'send' method sends garbage

6eed98d introduced a new problem to the send method. Its output looks like it is using uninitialized memory.

How to reproduce.

  1. run nc -l -n -p 8000 in a terminal
  2. send exec nc localhost 8000 to [command]
  3. send send one two three four five to [command]

What I get in the terminal:

��[l�one two three four jn5Vfive

What I would expect:

one two three four five

"old process still running" should be an error

for whatever reason it uses post(...) rather than pd_error(x,...).

post("old process still running");

i think it is the responsibility of the user to prevent such a case (e.g. by implementing their own queue).
in order to find the instance that lacks such a command queue, it would be nice to be able to just click the error message.

executables in /usr/local/bin not found in macOS 10.15

On Linux, [command] finds executables in /usr/bin/ and /usr/local/bin. On macOS 10.15 (Catalina), [command] only finds executables in /usr/bin, but not in /usr/local/bin. exec <command> where <command> is some binary from /usr/local/bin returns 2 on the left outlet, while the other outlets are silent.

numeric-only output is sent to the 1st outlet

consider a patch like this:

[exec echo foo(
|
[command]
|        |       |
|        |
|        [print stdout]
|
[print err]

this will have the printout:

stdout: foo
err: 0

compare this to a patch like this:

[exec echo 123(
|
[command]
|        |       |
|        |
|        [print stdout]
|
[print err]

this will have the printout:

err: 123
err: 0

i would have expected this instead:

stdout: 123
err: 0

Allow setting environment variables

Quoting an idea from @umlaeute:

"as an aside: it might be interesting to be able to set per-process environment variables (so you can manually add /usr/local/bin and /Users/reduzent/.backdoor/bin/ to your PATH).

setting envvars could be done via a simple [env( message to [command]. the only missing part is to query the current value of an envvar (my gut feeling tells me that [command] is not the right object for this; however you could already do something like [exec echo $PATH()"

Yeah, querying can already be done with [exec env( or [exec echo $VAR(

Allow blocking mode

It might be desirable in some situations to run [command] in blocking mode, so that order of execution is maintained, even if there is a [command] in the chain. Maybe this could be done with a flag -d (depth-first?) .

[loadbang]
|
[t b b]
|     |
|     [exec date (
|     |
|     [command  -d]
|  /
[print]

Would yield:

print: Do 24 Nov 2022 11:10:24 CET
print: bang

memleak

it seems that there is a memory leak in

argv[i] = getbytes(255);

it's probably not a big issue, as the data is allocated in the fork()ed process, which gets destroyed soon enough, but still...

also, 255 characters per argument seem to be a bit low. is there any specific reason to not use MAXPDSTRING?

clarify that `[command]` runs asynchronously

command forks of the command to execute, so Pd can continue to do it's thing while the command runs. nice.

however, i think this needs to be documented more explicitly.

so far the only thing in the help-patch that deals with this topic is a single sentence saying:

long running commands are not blocking

i think the "long" is misleading, as the blocking behavior is the same for short-running and long-running commands.
so probably "running commands are not blocking Pd" would be better.

also, the documentation should make it explicit that the output of [command] will break order of execution.

the following will always output the return code of the previous command (so on first run it will output 0)

|
[t b b]
|     [exec false(
|     [command]
|int  ]
|

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.