Loading files when ui_one_instance is true

tmsg
Posts: 120
Joined: 20.05.2020 12:08

Post by tmsg »

Alexey wrote:done as suggested. tested on Linux, -id=name works Ok.
:D Well done.

Seems this is supported for Linux and not the other platforms... any specific reason for that?

And while I am at this Linux-only stuff... using a pipe to feed text into Cud is also Linux only. Pipes work in Windows as well so what is the rationale behind that? Or is it an FP/Lazarus thing? (I don't use it much in Windows, so that's more a case of curiosity killing the cat.)

I will for now try to learn a bit more about Cud's plugin framework so no new :idea: 's or other :shock: tortures... for a while :D
Alexey
Posts: 1633
Joined: 05.10.2012 22:10

Post by Alexey »

pipe char is changed already. to CR or LF. after syncing UniqInstance with original repo.
Linux only? i'd say Posix only. Win32 build don't use UniqInstance.
tmsg
Posts: 120
Joined: 20.05.2020 12:08

Post by tmsg »

Alexey wrote:pipe char is changed already. to CR or LF. after syncing UniqInstance with original repo.
That's not what I meant with my question.

I mean this quote from https://wiki.freepascal.org/CudaText:
-i - Read the contents of stdin to a new document (Unix only), can be used in Unix shell like: "ls -l | cudatext -i"
Alexey
Posts: 1633
Joined: 05.10.2012 22:10

Post by Alexey »

aha. I see. "Linux only"? Linux and *BSD and Mac. Why not for Windows? Cud for Win32 is GUI app and cannot get console input
tmsg
Posts: 120
Joined: 20.05.2020 12:08

Post by tmsg »

Hm... I seem to remember vaguely that many years ago, in another life :D , I had solved this problem... so a win32 GUI app could read and write stdin and stdout. I have to search my old archives...
tmsg
Posts: 120
Joined: 20.05.2020 12:08

Post by tmsg »

So I climbed down and started digging through my old C archives and... (imagine Indiana Jones emerging from some deep underground tunnel, covered in cobwebs with spiders hanging off his hat, but holding up an ancient golden statue)... found this gem:

Code: Select all

#define WIN32_LEAN_AND_MEAN
#include "windows.h"
#include "io.h"
#include "fcntl.h"
#include "stdio.h"
#include "stdlib.h"
int WINAPI WinMain(HINSTANCE hInstance,HINSTANCE hPrevInstance,PSTR lpCmdLine,INT nCmdShow) {
	char buf[512]="";
	int i;
        // minimal version, just stdin
	FILE *fin;
	fin=_fdopen(_open_osfhandle((long)GetStdHandle(STD_INPUT_HANDLE),_O_RDONLY),"r");
	fread(buf,1,sizeof(buf),fin);
	if (fclose(fin)==0) MessageBox(NULL,buf,"OK",0);
}
This short snippet works if used with a redirected stdin:

Code: Select all

echo Something | testGuiStdin.exe
But how to translate that stuff into FP/Lazarus... I haven't got a clue. It's probably not even worth your while to try as the C runtime library does things differently to FP's, I'd assume. Nevertheless, in theory at least a Win32 GUI app can indeed read stdin if started from a console :twisted:
Alexey
Posts: 1633
Joined: 05.10.2012 22:10

Post by Alexey »

yes, I recall this gem too (made win32 console apps long time ago). don't know how to translate to FP, yes

edit.
and not sure we need this trick in Cud/win32.
Post Reply