好吧,我需要写一个用fork()获得的子进程的stdin.我还需要将stdin的文件描述符(?)保留到父进程以重复写入child.我os.pipe()用来获取描述符,所以请保持这种方式.
pid = fork()
if pid == 0:
os.write(sys.stdin.fileno(), "sample") # <-- isn't this the child's stdin?
os.execv(..)
.
.
Run Code Online (Sandbox Code Playgroud)
子进程是一个bash脚本,如:
#!/bin/bash
/usr/bin/mplayer -slave "$1" <&0
Run Code Online (Sandbox Code Playgroud)
显然,我想使用slave从其stdin接收命令的模式使用python控制mplayer
fork()是必不可少的,因为程序的结构,所以请不要使用communicate等等
对于Delphi或fpc中的嵌套异常处理,已经提到了很多东西.比如这样的东西.我的问题,也许解决了对嵌套try...块的需求,如果下面两个版本的代码之间存在实际差异,我没有看到任何除非未定义的行为或某事后发生expect或finally...
try
StrToInt('AA');
finally
writeln('I absolutely need this');
end;
writeln('and this');
Run Code Online (Sandbox Code Playgroud)
和...
try
StrToInt('AA');
except
end;
writeln('I absolutely need this');
writeln('and this');
Run Code Online (Sandbox Code Playgroud) program test;
uses
sysutils;
const
BUFLEN = 20;
var
Buf0: array[0..BUFLEN-1] of char;
Buf1: array[1..BUFLEN] of char;
s: string;
begin
// Fillchar...
// StrPLCopy...
SetString(s, Buf1, Length(Buf1));
// Error: Incompatible type for arg no. 2: Got "Array[1..20] Of Char", expected "PChar"
SetString(s, Buf0, Length(Buf0));
// compiles ok
end.
Run Code Online (Sandbox Code Playgroud)
在 C/C++ 中,我们经常使用数组名作为指针。在 Delphi 中,我们也可以像上面的例子那样实现。
尽管如此,Buf1在 FreePascal 中使用数组SetString()会导致错误,而Buf0数组工作得很好。数组的基本索引应该无关紧要,对吗?
是否有任何文件证明这种行为是合理的?
在 FPC 3.0.4 和 Delphi 10.3 中测试。
我需要覆盖NSMutableDictionary的valueForKey:方法.我想检查一个特定的值,做一些操作并返回它.我应该注意哪些要点?如果出现问题,请纠正我,例如:
- (id)valueForKey:(NSString*)key {
id val = [super valueForKey:key];
if([val isKindOfClass:[NSString class]] && [val isEqualToString:@"<null>"]) {
return @"No Value";
}
else {
return val;
}
}
Run Code Online (Sandbox Code Playgroud)
谢谢