how to read string from stdin and write to stdout?

Linux specific forum
sartic
Enthusiast
Enthusiast
Posts: 143
Joined: Thu Aug 26, 2010 8:26 am

how to read string from stdin and write to stdout?

Post by sartic »

I tried width console input and printn but it is not working.
Registered user of PB (on Linux Mint 21.1 & Win 10 64bit)
User avatar
ts-soft
Always Here
Always Here
Posts: 5756
Joined: Thu Jun 24, 2004 2:44 pm
Location: Berlin - Germany

Re: how to read string from stdin and write to stdout?

Post by ts-soft »

PureBasic 5.73 | SpiderBasic 2.30 | Windows 10 Pro (x64) | Linux Mint 20.1 (x64)
Old bugs good, new bugs bad! Updates are evil: might fix old bugs and introduce no new ones.
Image
sartic
Enthusiast
Enthusiast
Posts: 143
Joined: Thu Aug 26, 2010 8:26 am

Re: how to read string from stdin and write to stdout?

Post by sartic »

I read it but do not understand. I have to run program A and connect to it in connect, read & write mode?
What I want is:
program A spawns my program (B)
program A sends string to stdin of B
program B reads string from stdin
after each string program B sends string to stdout
program A receive data and send new string....

ps: i wrote squid url rewriter. A is squid (own by root) and B is my program.
Registered user of PB (on Linux Mint 21.1 & Win 10 64bit)
sartic
Enthusiast
Enthusiast
Posts: 143
Joined: Thu Aug 26, 2010 8:26 am

Re: how to read string from stdin and write to stdout?

Post by sartic »

I wrote small test program in win and nt port of squid. Input() is reading string from stdin but I can not figure what is (or do not know how to writeprogramstringn() ) writing to stdout.
Registered user of PB (on Linux Mint 21.1 & Win 10 64bit)
Fred
Administrator
Administrator
Posts: 18350
Joined: Fri May 17, 2002 4:39 pm
Location: France
Contact:

Re: how to read string from stdin and write to stdout?

Post by Fred »

You can use ReadProgramString() and WriteProgramString() if your program launch the subprocess. Then your child program can use PrintN() and Input()
sartic
Enthusiast
Enthusiast
Posts: 143
Joined: Thu Aug 26, 2010 8:26 am

Re: how to read string from stdin and write to stdout?

Post by sartic »

Thx 4 try but my program (B) is called by another (A).
From my testing in Windows for now... printN() is writing to stdout.
I change code a little bit and it works on Windows.
I will recompile in ubuntu 32bit later. Maybe problem is ownership (program A is own by root).
Registered user of PB (on Linux Mint 21.1 & Win 10 64bit)
sartic
Enthusiast
Enthusiast
Posts: 143
Joined: Thu Aug 26, 2010 8:26 am

Re: how to read string from stdin and write to stdout?

Post by sartic »

Solved! I enabled threadsafe compiler option.
Registered user of PB (on Linux Mint 21.1 & Win 10 64bit)
User avatar
Joakim Christiansen
Addict
Addict
Posts: 2452
Joined: Wed Dec 22, 2004 4:12 pm
Location: Norway
Contact:

Re: how to read string from stdin and write to stdout?

Post by Joakim Christiansen »

Fred wrote:You can use ReadProgramString() and WriteProgramString() if your program launch the subprocess. Then your child program can use PrintN() and Input()
What's annoying about this is that you have to open a console window first! (at least on Windows)
It would be a good idea to be able to write to stdout without the program opening a console window first.
EDIT: Okay, I spoke too soon... #PB_Program_Hide solves my problem! :D
I like logic, hence I dislike humans but love computers.
Post Reply