리디렉션의 콘솔 표준이 VLC 프로세스에서 작동하지 않음을 발견했습니다. 내가 작동시킬 수있는 VLC 콘솔 인터페이스를 얻을 수있는 유일한 방법은 SendKeys입니다.이 작업은 아주 좋은 방법이 아닙니다.
VLC는 동일한 인터페이스에 대한 소켓 연결도 지원합니다. 이것은 매우 잘 작동하는 것 같습니다. 다음은 명령과 응답을 연결하고 보내거나받는 방법의 예입니다.
static void Main()
{
IPEndPoint socketAddress = new IPEndPoint(IPAddress.Parse("127.0.0.1"), 54165);
var vlcServerProcess = Process.Start(@"C:\Program Files (x86)\VideoLAN\VLC\vlc.exe", "-I rc --rc-host " + socketAddress.ToString());
try
{
Socket vlcRcSocket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
vlcRcSocket.Connect(socketAddress);
// start another thread to look for responses and display them
Task listener = Task.Factory.StartNew(() => Receive(vlcRcSocket));
Console.WriteLine("Connected. Enter VLC commands.");
while(true)
{
string command = Console.ReadLine();
if (command.Equals("quit")) break;
Send(vlcRcSocket, command);
}
Send(vlcRcSocket, "quit"); // close vlc rc interface and disconnect
vlcRcSocket.Disconnect(false);
}
finally
{
vlcServerProcess.Kill();
}
}
private static void Send(Socket socket, string command)
{
// send command to vlc socket, note \n is important
byte[] commandData = UTF8Encoding.UTF8.GetBytes(String.Format("{0}\n", command));
int sent = socket.Send(commandData);
}
private static void Receive(Socket socket)
{
do
{
if (socket.Connected == false)
break;
// check if there is any data
bool haveData = socket.Poll(1000000, SelectMode.SelectRead);
if (haveData == false) continue;
byte[] buffer = new byte[socket.ReceiveBufferSize];
using (MemoryStream mem = new MemoryStream())
{
while (haveData)
{
int received = socket.Receive(buffer);
mem.Write(buffer, 0, received);
haveData = socket.Poll(1000000, SelectMode.SelectRead);
}
Console.WriteLine(Encoding.UTF8.GetString(mem.ToArray()));
}
} while (true);
}
팁 주셔서 감사합니다. 소켓은 놀라 울 정도로 쉽게 작동했습니다!. SendKeys는 개념의 단순한 증명을 위해 내가 찾고있는 종류의 Aproach입니다. 여전히 기대했던 것보다 훨씬 더 추악합니다. – Troveldom