Sending output from executable called from teraterm (exec prog.exe) to the teraterm terminal - teraterm

I have a simple executable, say prog.exe, that when called from a regular command prompt writes to stdout. To keep that part simple, say it simply writes "Hello World!":
int main(void)
{
printf("%s\n", "Hello World");//How to route to Teraterm terminal emulator
return 0;
}
Example source is written in C, but language does not matter, source code from any language that produces an executable that outputs to stdout should do.
I would like to know if there is a Teraterm API method to call the executable from within a Teraterm script in such a way that the output to stdout can be routed to show up on the Teraterm terminal emulator.
Invoking the executable using exec in a Teraterm script:
exec ./prog.exe
does not appear to result in anything being output to the Teraterm terminal emulator.

Related

How to force wineconsole to exit after program end and get ascii output to linux terminal?

I'm currently running windows application using this command line:
env WINEPREFIX=$HOME/winedotnet wineconsole --backend=curses app.exe 1.bin
However, this way has some drawbacks:
Wine does not close console until I press enter (normally, the console program exits after execution).
When I'm trying redirect output to the file, I receive the following (truncated):
^[[?1049h^[[22;0;0t^[[1;24r^[(B^[[m^[[4l^[[?7h^[[39;49m^[[?1h^[=^[[?12;25h^[[39;49m^[[37m^[[40m^[[H^[[2J^[(B^[[0;1m^[[37m^[[40m^[[J^[(B^[[m^[[39;49m^[[37m^[[40m^[[?25l^[[?12;25h^[]2;app.exe
The questions are:
Is it possible to force wine exit after program end?
How to redirect program output to file without the above control chars (only ascii and \r\n)?

How does Linux execute command inside

I was asked this question during an interview in Google, How does Linux/Unix execute your input command inside and what's the procedure?
I knew the shell didn't create a process for the command and use the shell process, but how does it work? does it different when we input a shell command like cd and a service like enable sshd sshd start?
I knew the shell didn't create a process for the command and use the shell process, but how does it work?
You must assume the shell creates a new process using fork(2) followed by exec(3). It happens the shell you are using have built-in commands, and then there is no new process in fact. i.e., time in Bash does not execute /usr/bin/time, but its own implementation.
How does Linux/Unix execute your input command inside and what's the procedure?
It is not clear to me what you mean by "execute your input command inside". I will consider you are asking how the shell pass the parameter you typed in the command line to your program.
The complete command line of the program you are spawning lays on the new process stack. Use argv pointer to reach it. Each interleaved space is exchanged by \0 which gives us an array of string(*).
argc is the size of this array. Thus, the main prototype can be
int main(int argc, char *argv[]);
For more information that is an excellent text about the stack layout in Linux.
(*) an exception to this is when you use \". Example:
$ echo hello world # broken into {"echo", "hello", "world"}
...
$ echo "hello world" # broken into {"echo", "hello world"}
...
does it different when we input a shell command like cd and a service like enable sshd sshd start?
cd is commonly implemented as a built-in command; it just changes the working directory by invoking chdir(2). On the other hand, sshd start implies in fork+exec (see GNU Libc manual). exec at some point will set up the stack of the new process created by fork and assign the command line string to argv.

Windows command prompt capture output of bash script in one step

I trigger a bash script from Windows command prompt.
postCloneSetup.sh
It opens another window and then returns. The window it spawned stays open and logs output text.
I want to capture the output from the spawned window and return that to the Windows command prompt.
I would prefer to use something like
$(postCloneSetup.sh) // Linux for capturing output to current context
for the Windows command prompt.
I'd prefer not to modify postCloneSetup.sh. I know I could have it write out to a file with
exec &> postCloneSetupLog.log
but then I must wait and manually run
type postCloneSetupLog.log
to see the output in the console. This is not possible for integrating into a CI engine, which is my goal.
How can I capture the output from the spawned console in one command?

Bash Shell Scrpiting, How can I write a script to run a program which ask for input?

I have a program, porodry, which will need read a parameters file to run, suppose the file called test1, so if I use bash
I can run
./porodry
terminal will show:
please input your parameters file name:
I will type
test1
then the program start to run, and will have some outputs shows on the terminal, like
Please input an int number:
then I will type something like:
1110
then the program will keep running.
I want to write a script, which will automatically read the input and output the terminal content to a test1.terminal file
Please help out!
It depends on what the program really does. If it just reads from the standard input, you cat just pipe the input to it and redirect the output to a file:
echo test1 | ./porodry > test1.terminal
If it messes with the terminal, you might need expect.

Output from TCL to running terminal

Basically i'm connecting to a cygwin terminal on another computer and running a program(CodeWarrior) that has TCL support. Running tcl commands inside the program is not a problem.
What i am trying is to redirect output (from puts for example) in tcl to my running cygwin console.
Provided the terminal is the current one, you can do this:
set terminal [open /dev/tty]
puts $terminal "Hi there!"
You might make the terminal handle a global one and never close it (until the program exits).
Other terminals can be written to — provided you have permission — by just opening the correct device. Or you can open a file descriptor if you can find it in /proc, though that's a little bit of a black art in itself.

Resources