在 Popen 中,我可以写入 stdin (0) 并从 stdout (1) 和 stderr (2) 读取。
我想做这样的事情:
#!/usr/bin/env python3
from subprocess import Popen, PIPE
with Popen(
[
'ffmpeg',
'-f', 'matroska', '-i', 'pipe:0',
'-f', 'matroska', '-i', 'pipe:3',
],
stdin=PIPE, in_3=PIPE) as p:
p.stdin.write(b'There is nothing special.')
p.in_3.write(b'\xf0\x9f\x99\x88\xf0\x9f\x99\x89\xf0\x9f\x99\x8a')
Run Code Online (Sandbox Code Playgroud) void swap(int* a, int* b) {
if (a != b)
*a ^= *b ^= *a ^= *b;
}
Run Code Online (Sandbox Code Playgroud)
由于以上*a ^= *b ^= *a ^= *b
只是一个快捷方式*a = *a ^ (*b = *b ^ (*a = *a ^ *b))
,可以(例如)第二个*a
被评估(对于XOR)就在第三个*a
被修改之前(由=)?
我是否用C99/C11/C++ 98/C++ 11编写它是否重要?
以下类不编译:
template<class Key, class Compare = std::less<Key>, class Allocator = std::allocator<Key>>
class MyContainer
{
public:
std::vector<Key, Allocator> data;
std::vector<std::pair<std::size_t, decltype(data)::size_type>> order;
};
Run Code Online (Sandbox Code Playgroud)
我得到以下编译器错误:
错误:模板参数列表中参数2的类型/值不匹配'template struct std :: pair'
为什么这不能编译,而以下代码工作正常?
template<class Key, class Compare = std::less<Key>, class Allocator = std::allocator<Key>>
class MyContainer
{
public:
std::vector<Key, Allocator> data;
std::vector<std::pair<std::size_t, std::size_t>> order;
};
Run Code Online (Sandbox Code Playgroud) 该程序将回显"C".我怎么不允许这样做?
import std.stdio;
void main() {
class A {
private void B() {
writeln("C");
}
}
auto D = new A;
D.B();
}
Run Code Online (Sandbox Code Playgroud) 我wodering为什么人们叫fork()
两次,为什么在执行第一个呼叫之前 setsid()
.
是的,如果调用者已经是进程组负责人,则不会创建新会话.但是,如果我不让(大)父母成为流程组组长呢?谁会为我做(不问我)?(好吧,也许1llum1n4t1,Sc13nt0l0gy,国家安全局,......;))
是的,第一个孩子应立即退出,不要创建僵尸进程.但是,(大)父母不能在分叉后退出吗?或者一两个fprintf(stderr,...
或者write(2,...
电话(如"成功启动守护程序xy")会是如此重要?(我不能以另一种方式阻止僵尸吗?)
总而言之,这种双重fork()
"神奇"真的需要(不要麻烦)吗?或者它只是传统或所谓的"最佳实践"(如避免goto
)?或者它是否只是保证守护进程能够处理"历史"(当然我的意思是"在生产环境中使用太旧")平台,如SVr4,BSD 3,RHEL 2或一些蹩脚的32位嵌入式平台?
using System.Windows.Forms;
public class App
{
[STAThread]
public static void Main()
{
string fname;
using (var d = new OpenFileDialog())
{
if (d.ShowDialog() != DialogResult.OK)
{
return;
}
fname = d.FileName;
}
//Application.ExitThread();
for (; ;)
;
}
}
Run Code Online (Sandbox Code Playgroud)
上面的代码显示了一个文件对话框.一旦我选择了一个文件并按下open
,就会执行for循环,但是(冻结的)对话框仍然存在.
取消注释后Application.ExitThread()
,对话框会按预期消失.
这是否按预期工作?为什么不让using
窗户消失?我在哪里可以找到更多关于此的信息?
在链接此代码时:
#include <map>
using std::map;
#include <string>
using std::string;
class C {
public:
static void dump() {
for (const auto& e : data) {
string(e.first);
}
}
private:
static map<string,map<string,string>> data;
};
int main() {
C::dump();
}
Run Code Online (Sandbox Code Playgroud)
...我收到此错误:
/tmp/cc4W2iNa.o: In function `C::dump()':
test.cpp:(.text._ZN1C4dumpEv[_ZN1C4dumpEv]+0x9): undefined reference to `C::data'
collect2: error: ld returned 1 exit status
Run Code Online (Sandbox Code Playgroud)
......来自g ++(GCC)4.9.1.我做错了吗?