我试图在C中实现一个shell.我可以用一个简单的execvp()来执行简单的命令,但其中一个要求是管理这样的命令:"ls -l | head | tail -4"with a for '循环并且只有一个'pipe()'语句重定向stdin和stdout.几天后,我有点迷失了.
N =简单命令的数量(示例中为3:ls,head,tail)命令=带有命令的结构列表,如下所示:
commands[0].argv[0]: ls
commands[0].argv[1]: -l
commands[1].argv[0]: head
commands[2].argv[0]: tail
commands[2].argv[1]: -4
Run Code Online (Sandbox Code Playgroud)
所以,我做了for循环,并开始重定向stdin和stdout以便用管道连接所有命令,但是...我只是无能为力它为什么不起作用.
for (i=0; i < n; i++){
pipe(pipe);
if(fork()==0){ // CHILD
close(pipe[0]);
close(1);
dup(pipe[1]);
close(pipe[1]);
execvp(commands[i].argv[0], &commands[i].argv[0]);
perror("ERROR: ");
exit(-1);
}else{ // FATHER
close(pipe[1]);
close(0);
dup(pipe[0]);
close(pipe[0]);
}
}
Run Code Online (Sandbox Code Playgroud)
我想要创建的是一系列childed进程:
[ls -l] ---- pipe ----> [head] ---- pipe ----> [tail -4]
所有这些进程都有一个root(运行我的shell的进程)所以,第一个父亲也是shell进程的一个孩子,我已经有点筋疲力尽了,有人可以帮助我吗?
我甚至不确定孩子是否应该是执行命令的孩子.
多谢你们 !!
我使用 JavaScript 图表程序 cytoscape.js 在网页中构建了一个图表。它根本不显示任何内容。但它也不会给出语法错误,除了关于为了缩放目的而接管鼠标的警告。
这是代码:
<style type="text/css">
#cy {
width: 90%;
height: 300px;
display: block;
}
</style>
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/cytoscape/3.14.0/cytoscape.min.js"></script>
<script type="text/javascript">
var cy = cytoscape({
container: document.getElementById('cy'), // container to render in
style: [ // the stylesheet for the graph
{
selector: 'node',
style: {
'background-color': '#666',
'label': 'data(id)'
}
},
{
selector: 'edge',
style: {
'width': 3,
'line-color': '#ccc',
'target-arrow-color': '#ccc',
'target-arrow-shape': 'triangle'
}
}
],
// initial viewport state:
zoom: 1,
pan: { x: 0, y: …Run Code Online (Sandbox Code Playgroud) 我有一个使用 SQL Server 设置的 Web 项目,现在必须迁移到 PostgreSQL。我使用 Entity Framework 6.0 版和最新版本的 Microsoft.AspNet.Identity 来管理用户凭据。我正在使用 VS2015 和 .NET Framework 452。
除了 AspNet.Identity 之外,该项目在 PostgreSQL 服务器上运行良好。当我尝试注册新用户或进行登录时,我收到此问题中描述的相同错误消息。相同的错误,相同的行,但问题已有 2 年的历史,给出的解决方案对我不起作用(我曾多次尝试 Add-Migration 和 Update-Database)。
其他一切作品,我已经检查过我的PostgreSQL数据库不不包含与AspNet.Identity任何表的项目是使用SQL Server时,即使他们自动创建。其他与模型相关的表存在并且正在工作。
谢谢你。
.net ×1
c ×1
c# ×1
charts ×1
cytoscape.js ×1
javascript ×1
pipe ×1
posix ×1
postgresql ×1
shell ×1