Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Full support pipes #217

Open
wants to merge 12 commits into
base: master
Choose a base branch
from
Open

Conversation

manux81
Copy link
Contributor

@manux81 manux81 commented Aug 16, 2021

These changes start a full pipes support.
In particular this branch introduces following commands:

  • > Save output to a file.
  • < Read input from a file.
  • | Send the output from one program as input to another program.

@jxsvoboda
Copy link
Contributor

I'm not sure if it's worth spending much time with Bdsh which is planned to be replaced, but it would make sense if you would be able to sort out the potential VFS issues that (supposedly) prevent UNIX-style pipes (not DOS-style pipes) to be implemented.

If I understand correctly, you have implemented so far a sort of DOS-style pipe, where the first command is executed, the output is sent to /tmp/pipe, then the second command is executed with input redirected from /tmp/pipe, etc?

How did you test it? The only command I could think of that can be reasonably used as a filter is "cat -s -". I tried it with < and it works (as bad as before with from x|cat -s -) but with "cat /demo.txt | cat -s -" I get an error "cannot open -". Also I would note that it would be nice to delete the temporary file. And the temporary file would be ideally created with tmpfile(), but if you need a name, you could at least generate it with tmpnam().

@manux81
Copy link
Contributor Author

manux81 commented Aug 17, 2021

Below you can find my tests:
1- > Save output to a file:
1A) ls > prova.txt
1B) alias pluto='ls'
pluto > prova.txt
1C) ls >

  • Print a parser error near \n

2-> Send the output from one program as input to another program.
I create a program called in2out like follow
int main() {
while (!feof(stdin)) {
size_t size = fread(str, 1, 255, stdin); // read from stdin
str[254] = 0;
fwrite(str, 1, size, stdout); // print read content out to stdout
}
return (0);
}

cat demo.txt | in2out

  1. < Read input from a file.
    No already test yet.

Actually I'm stopping test because I found a error in bdsh that it not depends by my code.
If you type follow commands in mainline version bdsh stops working:
help | to prova.txt
cat prova.txt

@manux81
Copy link
Contributor Author

manux81 commented Aug 18, 2021

With last version I checked follow example and it seems work:
cat demo.txt | cat -s -
it works with my test too:
cat demo.txt | in2out

@manux81
Copy link
Contributor Author

manux81 commented Oct 1, 2021

Hi @jxsvoboda, I done changes that you ask to me.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

2 participants