The first difference I can see is that "echo" adds a newline, but your perl does not. Try adding the newline:
my $cmd='{"command":["stop"]}' . "\n"; This is a wild guess! -----Original Message----- From: listas.correo via beginners <beginners@perl.org> Sent: Tuesday, January 16, 2024 6:26 AM To: beginners@perl.org Subject: Using UNIX domain sockets CAUTION: This email originated from outside of the organization. Do not click links or open attachments unless you recognize the sender and know the content is safe. Hi, I am trying to control mpv player using unix sockets but it looks like that perl is unable to send the string correctly. I run the following command: mpv --input-ipc-server=~/mpv.sock --idle=yes -v -v If I sent the string using system commands: $ echo '{"command":["stop"]}' | socat - ~/mpv.sock | jq { "data": null, "request_id": 0, "error": "success" } It works as expected and is accepted by mpv: [ipc_1] Client connected [cplayer] Run command: stop, flags=64, args=[flags=""] [ipc_1] Client disconnected Now I run this perl code: #!/usr/bin/perl use strict; use warnings; use IO::Socket::UNIX; my $mpv_socket = IO::Socket::UNIX->new( Type => SOCK_STREAM(), Peer => "$ENV{HOME}/mpv.sock", ) or die "socket failed: ",$!,"\n"; my $cmd='{"command":["stop"]}'; $mpv_socket->send($cmd); and it fails to send the correct text: [ipc_2] Client connected [ipc_2] Client disconnected [ipc_2] Ignoring unterminated command on disconnect. the message "Ignoring unterminated command on disconnect" is because the text sent does not seem to be correct and is ignored by mpv. For what reason could it be that the text sent does not end correctly? -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/ -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/