formulahendry / formulahendry/vscode-code-runner

code runner output is different from terminal output[Bug]

Open
#579 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
TypeScript
Stars
2.4k
Forks
351
PR merge metrics
No merged PRs in 30d

Description

- VS Code Version:
- OS Version:
- Code Runner Version:0.9.15

**Describe the bug**
code runner output is different from terminal output

**To Reproduce**
Steps to reproduce the behavior:
First, in terminal: g++ hm5.8.cpp -o hm5.8 -Wall && "/Users/huangrt01/Desktop/OSTEP/ostep-code/cpu-api/"hm5.8
Second, use the code runner to run the same program.

**Actual behavior**
the terminal outputs 5 lines(expected), but code runner outputs 6 lines.

**Expected behavior**
the output of code runner should have 5 lines.

**Screenshots**

![截屏2020-01-1116 09 48](https://user-images.githubusercontent.com/14976749/72201231-cdbcf500-348c-11ea-9e1c-e79f98954ec5.jpg)

![截屏2020-01-1116 09 12](https://user-images.githubusercontent.com/14976749/72201222-bbdb5200-348c-11ea-9b1c-5705686c0e82.jpg)

code:
`#include
//#include
#include
#include
#include
#include
#include
#include
#include
using namespace std;
int main(int argc,char*argv[]){
int fd[2];
if(pipe(fd)<0){
cerr<<"pipe failed\n";
exit(1);
}
char *p;
p = (char *)malloc(12 * (sizeof(char *)));

int rc1=fork();
if(rc1<0)
{
// fork failed; exit
cerr << "fork failed\n";
exit(1);
}
else if(rc1==0){
printf("hello, I am child (pid:%d)\n", (int)getpid());
close(fd[0]);
write(fd[1], "hello world\n", 12);
return 0; //否则会继续fork一个进程
}
else if(rc1>0){
printf("hello, I am parent of %d (pid:%d)\n",
rc1, (int)getpid());
}
wait(NULL);
int rc2 = fork();
if (rc2 < 0)
{
// fork failed; exit
cerr << "fork failed\n";
exit(1);
}
else if (rc2 == 0)
{
close(fd[1]);
read(fd[0],p,12);
printf("%s",p);
printf("hello, I am child (pid:%d)\n", (int)getpid());
return 0;
}
else if (rc2 > 0)
{
printf("hello, I am parent of %d (pid:%d)\n",
rc2, (int)getpid());
}
return 0;
}`

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.