Usenet comp.sys.vms (1990-2004)
 help / color / mirror / Atom feed
* Problem with C function 'system()'...
@ 1995-11-27  5:00 Carl J. Lambrecht
  1995-11-29  5:00 ` Brian Hibbert
  1995-11-29  5:00 ` Paul
  0 siblings, 2 replies; 6+ messages in thread
From: Carl J. Lambrecht @ 1995-11-27  5:00 UTC (permalink / raw)



I am developing an application in C on a VAX 4100 running OpenVMS 6.1, 
and I am having problems with using the system() function.  At one point, 
I use it to get a directory, and bring filenames into the program.  That 
works fine.  However, I can not seem to get it to execute the following:
	sysret=system(strcat("def sys$output ",redir_file));
The C code compiles, links, executes fine, but the command does not 
process during run time.  Any ideas?  Can I get around this by using 
getenv() and putenv()?  If so, how do I do this?   Any answers are most 
appreciated.  Please email me at work : clambrecht@kinesisinc.com
Thanks in advance...

-Carl Lambrecht
Kinesis Computing, Inc.



^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Problem with C function 'system()'...
  1995-11-27  5:00 Problem with C function 'system()' Carl J. Lambrecht
@ 1995-11-29  5:00 ` Brian Hibbert
  1995-11-29  5:00   ` Carl J Lydick
  1995-11-29  5:00 ` Paul
  1 sibling, 1 reply; 6+ messages in thread
From: Brian Hibbert @ 1995-11-29  5:00 UTC (permalink / raw)


"Carl J. Lambrecht" <cjlambre@mailbox.syr.edu> wrote:
>
>I am developing an application in C on a VAX 4100 running OpenVMS 6.1, 
>and I am having problems with using the system() function.  At one point, 
>I use it to get a directory, and bring filenames into the program.  That 
>works fine.  However, I can not seem to get it to execute the following:
>	sysret=system(strcat("def sys$output ",redir_file));
>The C code compiles, links, executes fine, but the command does not 
>process during run time.  Any ideas?  Can I get around this by using 
>getenv() and putenv()?  If so, how do I do this?   Any answers are most 
>appreciated.  Please email me at work : clambrecht@kinesisinc.com
>Thanks in advance...
>
>-Carl Lambrecht
>Kinesis Computing, Inc.

I suspect the command is "working", the problem is it isn't doing what 
you want.  The system() function spawns a subprocess, waits for it to 
complete, and returns the status from the call.  What you are doing is
changing SYS$OUTPUT for a temporary subprocess, I suspect you are trying 
to redirect the output of stdout.  

I don't know how to do this within C on a VAX (I have never tried it).  
I would probably use fprintf to specifically send the output redir_file.
If this would require massive code duplication, I would probably move
my output to a function that takes the output file as a parameter and 
either pass it stdout or the file handle for redir_file as needed.

Brian Hibbert
 




^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Problem with C function 'system()'...
  1995-11-27  5:00 Problem with C function 'system()' Carl J. Lambrecht
  1995-11-29  5:00 ` Brian Hibbert
@ 1995-11-29  5:00 ` Paul
  1995-12-01  5:00   ` Carl J Lydick
  1 sibling, 1 reply; 6+ messages in thread
From: Paul @ 1995-11-29  5:00 UTC (permalink / raw)


In article <Pine.SOL.3.91.951127234901.29475B-100000@forbin.syr.edu>, "Carl J.
Lambrecht" <cjlambre@mailbox.syr.edu> writes:

> I am developing an application in C on a VAX 4100 running OpenVMS 6.1, 
> and I am having problems with using the system() function.  At one point, 
> I use it to get a directory, and bring filenames into the program.  That 
> works fine.  However, I can not seem to get it to execute the following:
> 	sysret=system(strcat("def sys$output ",redir_file));
> The C code compiles, links, executes fine, but the command does not 
> process during run time.  Any ideas?  Can I get around this by using 
> getenv() and putenv()?  If so, how do I do this?   Any answers are most 
> appreciated.  Please email me at work : clambrecht@kinesisinc.com
> Thanks in advance...

Seen some replies to this one explaining why it doesn't work, have you tried:

	fclose (stdout);
	stdout = fopen (redir_file, "w");

Of course this will only redirect output for the program.

-- 
Paul Harris * Senior Technical Consultant * Jenson Technology Group * Bristol
                   personal email to ehteam@telecall.co.uk
               web home page http://www.telecall.co.uk/pharris/
                     fidonet 2:250/110.2 or 2:2500/502.17
               keywords: alpha vax vms c amiga clueless waster



^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Problem with C function 'system()'...
  1995-11-29  5:00 ` Brian Hibbert
@ 1995-11-29  5:00   ` Carl J Lydick
  0 siblings, 0 replies; 6+ messages in thread
From: Carl J Lydick @ 1995-11-29  5:00 UTC (permalink / raw)


In article <49hq59$lh4@nntpd2.cxo.dec.com>, Brian Hibbert <b_hibbert@csc32.enet.dec.com> writes:
=I suspect the command is "working", the problem is it isn't doing what 
=you want.  The system() function spawns a subprocess, waits for it to 
=complete, and returns the status from the call.  What you are doing is
=changing SYS$OUTPUT for a temporary subprocess, I suspect you are trying 
=to redirect the output of stdout.  

Your analysis of what happens is correct.

=I don't know how to do this within C on a VAX (I have never tried it).

You could use freopen(), or, before you do any I/O to stdout, you could
redefine SYS$OUTPUT, either via the SYS$CRELNM system service (which, for an
unprivileged user, will make a user-mode definition), or via
LIB$SET_LOGICAL (which will create a supervisor-mode definition).
--------------------------------------------------------------------------------
Carl J Lydick | INTERnet: CARL@SOL1.GPS.CALTECH.EDU | NSI/HEPnet: SOL1::CARL

Disclaimer:  Hey, I understand VAXen and VMS.  That's what I get paid for.  My
understanding of astronomy is purely at the amateur level (or below).  So
unless what I'm saying is directly related to VAX/VMS, don't hold me or my
organization responsible for it.  If it IS related to VAX/VMS, you can try to
hold me responsible for it, but my organization had nothing to do with it.



^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Problem with C function 'system()'...
  1995-11-29  5:00 ` Paul
@ 1995-12-01  5:00   ` Carl J Lydick
  1995-12-04  5:00     ` Paul
  0 siblings, 1 reply; 6+ messages in thread
From: Carl J Lydick @ 1995-12-01  5:00 UTC (permalink / raw)


In article <1995Nov29.152052.60@jenson.demon.co.uk>, paul_h@jenson.com (Paul) writes:
=Seen some replies to this one explaining why it doesn't work, have you tried:
=
=	fclose (stdout);
=	stdout = fopen (redir_file, "w");

Just out of curiosity, why use fclose() and fopen() when you've got freopen(),
which is there to do exactly what it you're attempting with fclose() and
fopen()?
--------------------------------------------------------------------------------
Carl J Lydick | INTERnet: CARL@SOL1.GPS.CALTECH.EDU | NSI/HEPnet: SOL1::CARL

Disclaimer:  Hey, I understand VAXen and VMS.  That's what I get paid for.  My
understanding of astronomy is purely at the amateur level (or below).  So
unless what I'm saying is directly related to VAX/VMS, don't hold me or my
organization responsible for it.  If it IS related to VAX/VMS, you can try to
hold me responsible for it, but my organization had nothing to do with it.



^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Problem with C function 'system()'...
  1995-12-01  5:00   ` Carl J Lydick
@ 1995-12-04  5:00     ` Paul
  0 siblings, 0 replies; 6+ messages in thread
From: Paul @ 1995-12-04  5:00 UTC (permalink / raw)


In article <49lphs$5q3@gap.cco.caltech.edu>, carl@SOL1.GPS.CALTECH.EDU (Carl J
Lydick) writes:

> =	fclose (stdout);
> =	stdout = fopen (redir_file, "w");
> 
> Just out of curiosity, why use fclose() and fopen() when you've got freopen(),
> which is there to do exactly what it you're attempting with fclose() and
> fopen()?

Of course freopen is shorter, I've just never used it in anger.

Nothing wrong with curiosity:

In the dim and distance past, when I was learning Vax C, I remembered doing an
experiment, "what if I close stdout", when that worked I tried adding a
"printf" statement to see what happened writing to a closed channel, finding
that also didn't crash I tried opening a new file on stdout.  My (unsurprising)
conclusion was that there was nothing "special" about stdout!

So my response to the post was based on the memory of something like:

	fclose (stdout);
	printf ("hello");
	stdout = fopen ("test", "w");
	printf ("again);

Paul Harris * Senior Technical Consultant * Jenson Technology Group * Bristol
                   personal email to ehteam@telecall.co.uk
               web home page http://www.telecall.co.uk/pharris/
                     fidonet 2:250/110.2 or 2:2500/502.17
               keywords: alpha vax vms c amiga clueless waster



^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~1995-12-04  5:00 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
1995-11-27  5:00 Problem with C function 'system()' Carl J. Lambrecht
1995-11-29  5:00 ` Brian Hibbert
1995-11-29  5:00   ` Carl J Lydick
1995-11-29  5:00 ` Paul
1995-12-01  5:00   ` Carl J Lydick
1995-12-04  5:00     ` Paul

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox