I am new in NamedPipe concept on Linux/Centos 7. I want to implement read write funtions between my Windows and CentOS PC using NamedPipe. I have created a NamedPipe on CentOS PC using mkfifo function and written some text on this pipe.
On other side(Windows PC), I want to read that text written on NamedPipe. I have tried to use both CreateFile and open function for Pipe handle. I have successfully got the handle of Pipe but ReadFile and read function failed.
What I have tried:
I have created a NamedPipe on CentOS PC using mkfifo function.
int res; res = mkfifo("fifo1",0777); //creates a named pipe with the name fifo1
and written some text on this pipe.
Now I want to perform Read and write operations on NamedPipe on my Windows PC.
I will really appreciate if any one can help me out with that issue.
Related
I want to make a wrapper around stockfish (chess engine) that uses UCI (Universal chess interface). Running stockfish from the terminal will open its shell:
Stockfish 8 64 by T. Romstad, M. Costalba, J. Kiiski, G. Linscott
|
(where I - cursor)
it waits input commands (like go, position, setoption, etc...)
I need to read output of e.g. go command.
It is the same if i wanted to receive select * from * connecting to database with mysql, psql or another DBMS executable or to read some output from python command using python executable
I'm using linux, but crossplatform solutions are more preferable
I tried to make a program using popen and fscanf in while loop but i guess i need something non-blocking current thread while waiting output from stdout
Read a file using a program like Notepad while the file is being written to by another program?
I've created a Windows Service application that logs continuously.
I want to inspect the current events of the service without closing it. To do this I open the log.txt in Notepad, but gets the message
The process cannot access the file because it is being used by another
process
How can I read the log file without closing the service? After the service is closed, I can readily inspect every log entry in the file.
The file is being written by calls to fopen_s and fprintf, if that should be of any interest. Also, the service is programmed in C/C++ on Windows 10 64-bit, running under SCM with default priviledges i.e. LocalSystem.
https://msdn.microsoft.com/en-us/library/z5hh6ee9.aspx and then Remarks:
Files that are opened by fopen_s and _wfopen_s are not sharable. If you require that a file be sharable, use _fsopen, _wfsopen with the appropriate sharing mode constant—for example, _SH_DENYNO for read/write sharing.
Would that be a solution?
I'm creating a program which downloads a file from an FTP server. I want to display the progress of how much bytes the user has downloaded. I have tried searching for it but I couldn't find anything. First , my plan was to get the file size using fstream but then I realized that I can't share 2 processes at the same time.
I assume you're using FtpGetFile(..) to download the file from the FTP server. This is the simple way of downloading a file which gives you no information about how many bytes are already downloaded and you have very little control how the function behaves (e.g. cancelling of a download upon user request?). For quick test it is very helpful, though.
In order to monitor the download progress do the following:
Determine size of remote file using FtpFindFirstFile.
Open remote file using FtpOpenFile.
Create local file using CreateFile.
Read some bytes from remote file using InternetReadFile.
Evaluate return value and error code of InternetReadFile the detect errors and if transmittion is complete.
Write these bytes to local file using WriteFile.
Calculate/Update your progress information.
Go back to step 4 if file is not downloaded entirely and there is no error.
Close local file using CloseHandle.
Close remote file using InternetCloseHandle.
If you need more help I can offer some code doing this...
Several months ago, I implemented a named pipe server in a GUI using the example code from MSDN -> https://msdn.microsoft.com/en-us/library/bb546085.
The named pipe server seems to work well, and I've used it to control my GUI with other programs written in various Visual Studio languages.
Today I have been trying to interact with the named pipe server with a Python script. On the web, it was simple to find sample python code, using the ctypes library, that opened up the named pipe with the windll.kernel32.CreateFileA() method and wrote ASCII bytes to it with the windll.kernel32.WriteFile() method.
The problem is that the MSDN example uses a format where the first two bytes written to/received from the pipe represent the size of a string that is to follow in the pipe. While I can write strings to the pipe from Python with no problem, I can't seem to pass any binary data into the WriteFile() method.
Questions about ways to solve this problem:
1. Is there any way to write raw bytes of binary data to WriteFile()? Is there another method I could be calling to handle this?
2. Is there any way for me to encode the binary number into a string as raw bytes? For example, if I knew the bytes I wanted to send ahead of time (0x1234 for example) then I could just send create_string_buffer("\x12\x34"). The bytes have to be determined at runtime, however, and I haven't found a way to create a string out of the raw bytes.
I want to run an application in c++ and read its stdout and write t stdin in windows? No popup should be generated.
Can I do it easily using windows services?
I found that I maybe able to do this with POCO, but do I really need this?
Is there solution in std library for this?
You can spawn a child process and then gain access to its stdin and stdout pipes. You have to use WinAPI to achieve this. See example here: http://msdn.microsoft.com/en-us/library/ms682499(v=vs.85).aspx
You may use Qt and it's QProcess class to read/write child process output/input.