我试图从python程序控制mplayer的数量.mplayer程序从bash脚本开始:
#!/bin/bash
mkfifo /home/administrator/files/mplayer-control.pipe
/usr/bin/mplayer -slave -input file=/home/administrator/files/mplayer-control.pipe /home/administrator/music/file.mp3
Run Code Online (Sandbox Code Playgroud)
然后我有一个用Python编写的GUI,它应该能够控制正在播放的mplayer实例的音量.我尝试过以下方法:
os.system('echo "set_property volume $musicvol" > /home/administrator/files/mplayer-control.pipe')
Run Code Online (Sandbox Code Playgroud)
如果我用数字值代替$ musicvol,那就行了,但遗憾的是没有用.我需要能够传递变量.
我也可以通过调用Python应用程序中的bash脚本来解决它,但我无法让它工作:
subprocess.call("/home/administrator/files/setvolume.sh", executable="bash", shell=True)
Run Code Online (Sandbox Code Playgroud) 我正在使用FIFO和select()系统命令运行测试.这个想法是:
select()命令等待来自FIFO的消息所以这里是代码注意我正在进行错误检查以节省空间:
//process 1's code
int main()
{
int fd, ret;
fd_set rfds;
char buffer[100] = {0};
char * myfifo = "/tmp/myfifo";
struct timeval tv;
tv.tv_sec = 5; // 5 second sleep
tv.tv_usec = 0;
mkfifo(myfifo, 0666); //Make the fifo
fd = open(myfifo, O_RDONLY);
FD_ZERO(&rfds); // clear the flags
FD_SET(fd, &rfds); // set "read" on fd
while((ret = select(fd+1, &rfds, NULL, NULL, &tv)) <= 0) //should be 1 when we're ready …Run Code Online (Sandbox Code Playgroud) 在我的代码中,我创建了一个名为"my_fifo"的fifo,如果我在O_WRONLY | O_NONBLOCK模式下打开它,open()返回-1并且错误号为"No such device or address",另一方面,如果我打开fifo in O_RDONLY | O_NONBLOCK模式,它完美地运作.为什么会这样?有什么我做错了吗?
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <unistd.h>
#include <stdio.h>
#include <stdlib.h>
int main(int argc, char *argv[])
{
char *fifoname = "my_fifo";
mkfifo(fifoname, 0666);
int fd;
if ((fd = open(fifoname, O_WRONLY | O_NONBLOCK)) == -1)
{
perror("open pipe");
exit(EXIT_FAILURE);
}
close(fd);
exit(EXIT_SUCCESS);
}
Run Code Online (Sandbox Code Playgroud) 我想删除列表中最旧的(即第一个)元素,这样该列表永远不会超过100个元素.
我想过:
L = [327983, 232382, 1, 2, 3, 4, 5, 6, 23]
if len(L) > 100:
for i in range(len(L)-100):
del L[0]
print L # [4, 5, 6, 23]
Run Code Online (Sandbox Code Playgroud)
是否有一个没有迭代的解决方案(或更一般地说:一个更好的解决方案)来修剪列表的开头,以便它有<= 100个元素?
旁注:为此目的,除了列表之外,还有其他什么吗?即具有最大大小的数据结构,并且如果有更多数据,则删除最旧的数据!(这让我想到FIFO?Stack?Pipe?)
在客户机-服务器程序,需要检查EOF为read()上FIFO?
问题:
0,或者-1并将errno设置?@更新
我仍然发现结果有效,所以需要继续询问它。
cs_fifo.h:
// fifo header
#ifndef _CS_FIFO
#define _CS_FIFO
#define CLIENT_DATA_SIZE 2
#define SERVER_DATA_SIZE 10
#define SERVER_FIFO_PATH "/tmp/server_fifo"
#define CLIENT_COUNT 3
#endif
Run Code Online (Sandbox Code Playgroud)
fifo_server.c:
// client - server fifo, server part,
#include <stdio.h>
#include <fcntl.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <unistd.h>
#include <stdlib.h>
#include <string.h>
#include <errno.h>
#include "cs_fifo.h"
int fifo_server() {
int flag;
int fd;
char buf[CLIENT_DATA_SIZE];
// remove fifo, …Run Code Online (Sandbox Code Playgroud) 我想创建一个命名管道,然后写入它,然后我想读取它。这是我的代码:
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <errno.h>
#include <string.h>
#include <fcntl.h>
#define FIFO "fifo0001"
int main(intargc, char *argv[]){
char input[256];
FILE *fp;
char str[50];
printf("Please write some text:\n");
scanf("%s", input);
unlink(FIFO); /* Because it already exists, unlink it before */
umask(0);
if(mkfifo(FIFO, 0666) == -1){
printf("Something went wrong");
return EXIT_FAILURE;
}
if((fp = fopen(FIFO, "a")) == NULL){
printf("Something went wrong");
return EXIT_FAILURE;
}
fprintf(fp, "%s", input);
if(fgets(str, 50, fp) != NULL){
puts(str);
}
fclose(fp); …Run Code Online (Sandbox Code Playgroud) 所以我试图了解用于在我的队列中创建 FIFO 的 Azure 服务总线会话 ID。
我的想法非常直接,但我不知道在 FIFO 方面是否正确。
我在想在我的队列中创建 FIFO 的这些步骤中:
创造:
首先:检查消息队列及其会话 ID 并公开 ID 层次结构。
Next:使用层次结构中最新的 Session-ID 创建新消息并将该值迭代 1 (+1)
下一步:发送到服务总线队列。
阅读:
首先:检查消息队列及其会话 ID 并公开 ID 层次结构。
下一步:读取并删除层次结构中最早的会话 ID。
下一个:过程...
请记住,我没有包括错误处理,例如读取和删除部分,因为我已经弄清楚了。
所以问题是这是正确的思维方式,而且,我如何在 C# 中实现这一点,我真的无法找到以直接方式解释这个概念的东西。
在 AWS SQS FIFO 的队列中;当已读消息的可见性超时时,消息将位于队列的哪个位置?
例如:
消息的新顺序是什么?
我有 2 个不相关的进程。第一个创建一个 FIFO 通道并将数据写入其中。
测试组合:
int main(int argc, char *argv[])
{
int f1;
char *send_buf = "Hello";
char recv_buf[128] = {0};
if (mkfifo("mk.fifo", S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH) == -1 && errno != EEXIST)
error(0, errno, "mkfifo() error");
f1 = open("mk.fifo", O_RDWR);
perror("Opening ");
printf("Sending string '%s'...\n", send_buf);
write(f1, send_buf, strlen(send_buf));
perror("Writing ");
close(f1);
return 0;
}
Run Code Online (Sandbox Code Playgroud)
第二个进程应该从先前创建的通道读取数据。
test2comp:
int main(int argc, char *argv[])
{
int f2;
char recv_buf[128] = {0};
f2 = open("mk.fifo", O_RDONLY|O_NONBLOCK);
perror("Opening "); …Run Code Online (Sandbox Code Playgroud)