View topic - script a file using system command

script a file using system command

anything that doesn't fit to other groups.

script a file using system command

Postby rashidmirza » Wed Aug 10, 2011 7:31 pm

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):

2) 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
rashidmirza
Active Member
 
Posts: 55
Joined: Sun Jun 13, 2010 4:32 am

Re: script a file using system command

Postby maschoen » Sun Aug 14, 2011 8:44 am

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");
maschoen
QNX Master
 
Posts: 2715
Joined: Wed Jun 25, 2003 5:18 pm

Re: script a file using system command

Postby rashidmirza » Sun Aug 14, 2011 7:17 pm

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.
rashidmirza
Active Member
 
Posts: 55
Joined: Sun Jun 13, 2010 4:32 am

Re: script a file using system command

Postby maschoen » Mon Aug 15, 2011 4:41 am

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.
maschoen
QNX Master
 
Posts: 2715
Joined: Wed Jun 25, 2003 5:18 pm

Re: script a file using system command

Postby mario » Mon Aug 15, 2011 5:08 pm

How about popen() ?
mario
QNX Master
 
Posts: 4132
Joined: Sun Sep 01, 2002 1:04 am

Re: script a file using system command

Postby noc » Tue Aug 16, 2011 6:06 am

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

maschoen, I guess the OP meant literal "script", not a shell script:
http://www.openqnx.com/static/neutrino/ ... cript.html
"script" is interactive in nature, not sure how to automate it.
noc
Senior Member
 
Posts: 1634
Joined: Sat Jul 06, 2002 4:34 am

Re: script a file using system command

Postby maschoen » Tue Aug 16, 2011 6:14 am

noc,

You may be right, but after asking twice what "script" does I didn't get an answer.
maschoen
QNX Master
 
Posts: 2715
Joined: Wed Jun 25, 2003 5:18 pm

Re: script a file using system command

Postby rashidmirza » Wed Aug 17, 2011 5:51 am

hello

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

http://www.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
rashidmirza
Active Member
 
Posts: 55
Joined: Sun Jun 13, 2010 4:32 am

Re: script a file using system command

Postby rashidmirza » Wed Aug 24, 2011 4:40 am

Hello

is there any update on this problem? :)
rashidmirza
Active Member
 
Posts: 55
Joined: Sun Jun 13, 2010 4:32 am


Return to General Programming

Who is online

Users browsing this forum: No registered users and 1 guest