script a file using system command

i want to enable scripting, and then run a series of other commands using the system command.
In my code, i am trying to run :

  1. system("script testfile’);

from within a photon application, and then want to run another set of commands, and all the output of these commands has to be recorded the in testfile.

I have noticed, the moment i run the ‘system("script testfile’);’ the script starts, but is waiting for further inputs from that terminal window.
So even if i do after statement 1):

  1. system(“pwd”);

it is not recognised, as it has not been a input via keyboard.

is there any way round this??
that windows will close if i type ‘exit’, but then that will stop the logging of all text from terminal window.

regards

This is pretty confusing. The system() call will create a shell, which will try to start a program “script” with a parameter testfile. So what was it you were trying to do? Do you have a program called script? Does it use the 2nd parameter as an output file?

For the 2nd part of your question, how about system(“pwd >>testfile”);

the script here refers to the qnx command ‘script’, i.e:
Create a typescript of a terminal session

what i would like to do is log everything in a terminal session to the 2nd parameter which is a text file.
normally the user would type in command “script testfile”, then run a series of commands, that he would enter from the terminal window, and the result of these would get logged for later use or analysis.
I want to automate the process (first by starting the script from a system command), where:
a) start the script, and start logging to a file
b)provide the user with a GUI, where if the user clicks certain buttons, i make call to those commands using “system” command

the issue issue is, the moment the ‘script testfile’ is started, the prompt is available in the terminal window, and therefore i cannot make any use of ‘system’ command.

going back to my previous example, if i do from within the application:

system(“script testfile”);
system(“chkfsys -f /”);

the idea being that all chkfsys output in the terminal window gets written to text file “testfile”.
the moment :
system(“script testfile”);

is executed, the prompt is available in the terminal window and the program would wait for a keyboard input from that prompt, until i type exit, then program would resume execution from:
system(“chkfsys -f /”);

then at this point, there would not be any logging of the chkfsys result.

I hope this clears any doubts.

Each time you run system() you get a new shell. Each time system() returns, that shell is gone.

If you run a script from a pterm running sh, you can redirect the output.

But pterm and sh are programs that do what they do, and you don’t have control over them, say from a GUI program.

There are games you can play by inserting text into the input stream, but this is tricky. There are two approaches. The generic way is to emit photon events that have the text. This will only work under Photon. The other way involves finding out how to insert characters into a tty input stream. You would also have to find out which tty is involved, which is also tricky.

Just my opinion here, but you seem to be thinking about this the way a user things about computer problems. Sometimes that works but in this case, I suggest you find someone who thinks about things the way a programmer does.

How about popen() ?

maschoen, I guess the OP meant literal “script”, not a shell script:
openqnx.com/static/neutrino/ … cript.html
“script” is interactive in nature, not sure how to automate it.

noc,

You may be right, but after asking twice what "script" does I didn't get an answer.

hello

as rightly pointed out by noc, script is as per the following description:

qnx.com/developers/docs/6.3. … cript.html

i have clarified script definition earlier :

“the script here refers to the qnx command ‘script’, i.e:
Create a typescript of a terminal session”

regards

Hello

is there any update on this problem? :slight_smile: