Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Send Multiple Commands to External Program

We are trying to write a PowerShell script that invokes an external application -- a Redis client (redis-cli.exe) -- and then sends multiple commands to that .exe. We have no issue sending individual commands like the below:

& redis-cli -h localhost -p 6379 SMEMBERS someKey

The problem is that this will start a Redis client, issue a single command, close the client, and then return control to PowerShell. We need to issue multiple commands in a transaction. For example, here are the commands that we want to send to the client:

MULTI
DEL someKey
DEL someSet
EXEC

The Redis client does support sending a LUA script string as a command, but this unfortunately doesn't support the MULTI/EXEC transactional commands. In other words, we need to be able to issue multiple commands like I listed above.

like image 847
jakejgordon Avatar asked Sep 03 '15 11:09

jakejgordon


1 Answers

Since redis-cli appears to read input from STDIN you could feed it an array with the command strings like this:

'MULTI', 'EXEC' | & redis-cli -h localhost -p 6379

Using echo (alias for Write-Output) is not required for feeding the array into the pipeline.

You could also store the command array in a variable first:

$cmds = 'MULTI', 'EXEC'
$cmds | & redis-cli -h localhost -p 6379
like image 66
Ansgar Wiechers Avatar answered Oct 29 '22 17:10

Ansgar Wiechers