Hey everyone!
One of my mix tasks needs to use System.cmd. It is technically calling another mix task, but Mix.Task.run is not on the table (for a whole bunch of reasons that I don’t think are worth getting into right now).
However, this cmd I’m calling may prompt for input potentially. By default System.cmd does not forward stdin from the elixir process to the the System.cmd process. I’m not the most familiar with how all this works, only a layman’s knowledge of linux stdio piping etc.
So, I’ve found an option to System.cmd that seems like it should do what I need, but it has its own quirks and problems that make it effectively unusable as far as I can tell. The option is use_stdio: false.
I’ve got an example project here: GitHub - zachdaniel/mix-task-example · GitHub
Warning: this is broken and will start printing numbers to your terminal in such a way that you can’t stop without exiting that terminal window. Should be harmless, but just want to make it clear.
To reproduce the behavior I’m seeing, run mix example.run and enter a number. It will start counting up.
There are two problems:
-
it seems to just occasionally “miss” the input? i.e sometimes I type a number, hit enter, and its like nothing happened? I press enter again, and then it’s like I provided an empty string to the input. As if there was some “lag time” before it is accepting input?
-
Most importantly (well, they are both important), but it seems to leave zombie processes running after pressing Ctrl+C to quit the process.
From what I can tell, ports are a way to do this sort of thing, and if I must go down that route I will, but it seems like a very low level API w/ lots of fiddly bits, so I’m looking for simpler alternatives.
I’d also prefer not to reach for an external library, but I can if I must. This is for the igniter package, and I want to keep its footprint light.
Thanks in advance!






















