mirror of
https://github.com/ddnet/ddnet.git
synced 2024-11-18 05:58:19 +00:00
7eb5966f6f
Reimplement the Linux FIFO file server and client controls on Windows by using Named Pipes. The DDNet server/client acts as a named pipe server and receives messages. Messages can be posted to the named pipe server by connecting to it as a client. The named pipe client can for instance be controlled from the command line with PowerShell. The PowerShell script `scripts/send_named_pipe.ps1` is added for this purpose. For example the PowerShell command `./send_named_pipe.ps1 "testpipe" "echo a"` sends the command `echo a` to the pipe named `testpipe`. Multiple commands can be sent at the same time by separating them with semicolons or newlines.
34 lines
1 KiB
PowerShell
34 lines
1 KiB
PowerShell
# This PowerShell script connects to a Named Pipe server,
|
|
# sends one message and then disconnects again.
|
|
# The first argument is the name of the pipe.
|
|
# The second argument is the message to send.
|
|
if ($args.length -lt 2) {
|
|
Write-Output "Usage: ./send_named_pipe.ps1 <pipename> <message> [message] ... [message]"
|
|
return
|
|
}
|
|
|
|
$Wrapper = [pscustomobject]@{
|
|
Pipe = new-object System.IO.Pipes.NamedPipeClientStream(
|
|
".",
|
|
$args[0],
|
|
[System.IO.Pipes.PipeDirection]::InOut,
|
|
[System.IO.Pipes.PipeOptions]::None,
|
|
[System.Security.Principal.TokenImpersonationLevel]::Impersonation
|
|
)
|
|
Reader = $null
|
|
Writer = $null
|
|
}
|
|
$Wrapper.Pipe.Connect(5000)
|
|
if (!$?) {
|
|
return
|
|
}
|
|
$Wrapper.Reader = New-Object System.IO.StreamReader($Wrapper.Pipe)
|
|
$Wrapper.Writer = New-Object System.IO.StreamWriter($Wrapper.Pipe)
|
|
$Wrapper.Writer.AutoFlush = $true
|
|
for ($i = 1; $i -lt $args.length; $i++) {
|
|
$Wrapper.Writer.WriteLine($args[$i])
|
|
}
|
|
# We need to wait because the lines will not be written if we close the pipe immediately
|
|
Start-Sleep -Seconds 1.5
|
|
$Wrapper.Pipe.Close()
|