How to write a Signal message using command line? - bash

I'm trying to write a message on the Signal app only using command lines.
What I think I need to do is : echo "Hello World" > &fd_of_Signal
In Linux there is a file like : '/proc/pid_of_app/fd/0' but I didn't find it on MacOs.
So I need to find the FD with the lsof command.
I used the command lsof -c Signal to get every opened Signal files.
I end up having lots of Signal files opened, with a lot of different FD (in FD column), from 0r to 41.
When I use the lsof command for another app (like Spotify), I have the exact same numbers in FD column.
My questions are : How can I differentiate which FD number should I use ? If they are similar for both apps, how can I make my command line understand that I want to use the fd for Signal and not Spotify ? In Linux, there is a file '/proc/pid_of_app/fd/0', is there something similar on MacOs ?

Related

Send signal with data from bash script

I want to send a signal to a process including data (int) from a bash script. I know how to do that from a C program but I didn't find the way if exists from a script.
Note : Pipe isn't an option

Input redirection after program has started running

Is there a way to use input redirection after the program has started?
For example I want to run a program, scrape some data from it, then use that data to push it + some static data (from a file) to std input:
1 ./Binary
2 Hello the open machine is: computer2
3 Which computer:command do you want to use:
4 <<< "computer2:RunWaterPlants"
I want to redirect line 4 in using some program output from line 2.
I've tried Keeping a bash script running along the program it has started, and sending the program input, but it will just continue with the program execution without waiting for my input.
I can't edit ./Binary.
I found Write to stdin of a running process using pipe and it works for what I'm asking, but I can't see the stdout when I run it with pipe.
I figured it out from Writing to stdin of a process. Pretty much I started a fifo pipe and wrote to it and let it listen for input.

fastest command, which accepts pipe, but generates no text on StdOut & StdErr

Which command in Windows command script (.cmd) accepts pipe (so, no error "The Process tried to write to a nonexistent pipe." generated), but generates no output itself, including output to StdErr? I need to not touch normal StdErr output (keep in mind, pipe transports only StdOut). I can't use null device, due to it's not installed in the system.
For example, command|rem generates mentioned error. But I want no error output, except generated by command, so rem is not suitable command for needed purpose.
Main aim is the script speed. So, don't offer extensive constructions, please.
should be break(or set/p= ?) as it is internal command prompt command (i.e. no external process started ) and generally do nothing.Though I suppose if you are searching for executable packed with the windows answer will be different.
The cd . command is what you are looking for. I used it to create empty files. This way, command | cd . works and echo Hello >&2 | cd . show "Hello" in the screen! This works as a filter that just blocks Stdout (interesting).

How do I print Selenium Webdriver (Ruby binding) test results to a notepad file from command?

I wish to put the text from command prompt into a text file once the test is run. How do we do that
?
Just use a pipe >. Worth to look Using command redirection operators.
ruby test.rb > file.txt
Redirection operator and description
> : Writes the command output to a file or a device, such as a printer, instead of the Command Prompt window.
< : Reads the command input from a file, instead of reading input from the keyboard.
>> : Appends the command output to the end of a file without deleting the information that is already in the file.
>& : Writes the output from one handle to the input of another handle.
<& : Reads the input from one handle and writes it to the output of another handle.
| : Reads the output from one command and writes it to the input of another command. Also known as a pipe.

Terminal emulator implementation - problems with repeated input

I am trying to implement a terminal emulator in Java. It is supposed to be able to host both cmd.exe on Windows and bash on Unix-like systems (I would like to support at least Linux and Mac OS X). The problem I have is that both cmd.exe and bash repeat on their standard output whatever I send to their standard input.
For example, in bash, I type "ls", hit enter, at which point the terminal emulator sends the input line to bash's stdin and flushes the stream. The process then outputs the input line again "ls\n" and then the output of the ls command.
This is a problem, because other programs apart from bash and cmd.exe don't do that. If I run, inside either bash, or cmd.exe, the command "python -i", the python interactive shell does not repeat the input in the way bash and cmd.exe does. This means a workaround would have to know what process the actual output came from. I doubt that's what actual terminal emulators do.
Running "bash -i" doesn't change this behaviour. As far as I know, cmd.exe doesn't have distinct "interactive" and "noninteractive" modes.
EDIT: I am creating the host process using the ProcessBuilder class. I am reading the stdout and stderr and writing to the stdin of the process using a technique similar to the stream gobbler. I don't set any environment variables before I start the host process. The exact commands I use to start the processes are bash -i for bash and cmd for cmd.exe. I'll try to post minimal code example as soon as I manage to create one.
On Unix, run stty -echo to disable "local echo" (i.e. the shell repeating everything that you type). This is usually enabled so a user can edit what she types.
In your case, BASH must somehow allocate a pseudo TTY; otherwise, it would not echo every command. set +x would have a similar effect but then, you'd see + ls instead of ls in the output.
With cmd.exe the command #ECHO OFF should achieve the same effect.
Just execute those after the process has been created and it should work.

Resources