Re: Talking to *n*x

From: Eric Sosman (Eric.Sosman_at_sun.com)
Date: 06/01/04


Date: Tue, 01 Jun 2004 15:15:11 -0400

robbie carlton wrote:
> reposted (after stern words :-) from comp.lang.c
>
> I understand that c was originally designed to write and communicate
> with the unix operating system. Until recently I ignored this, as I
> was mostly polaying with opengl. I am now interested in interacting
> more directly with the operating system (actually linux) and I was
> wondering if anyone has any advice/urls. Specifically, I've found the
> system() function, which almost does what I want. But, while I could
> do something like
>
> system("cd /me/home/somedir");
> system("mkdir somesubdir");

     You could certainly do that, but it would not do
what you probably desire unless your cwd is already
/me/home/somedir. If you're adept at writing shell
scripts (as is hinted below), you should understand
why: What happens to a parent shell's cwd when a script
in a sub-shell executes 'cd'?

> which is cool. But what if I want to get information /from/ the OS?
> say I just want to get the output of a ls command. Do I have to do it
> all with system() calls and environment variables? If so, I may as
> well write a shell script.

     As usual, the tool depends on the task. To get
output from or (not "and/or") feed input to a sub-process,
consider popen(). For finer control of sub-processes,
see fork() and the various flavors of exec(). To do
the job unaided in your own process, see the documentation
for the system calls and/or library functions that do
what you need -- for an 'ls' clone, opendir() and readdir()
seem a good start.

> Anyhoo, ta.

     Anyha, too.

-- 
Eric.Sosman@sun.com


Relevant Pages

  • Re: How to find the operating system bit (x86/x64/ia64)
    ... Reading back, I realize there was one point that I may not have made explicit: the values represent an OS architecture, not necessarily a specific manufacturer. ... AMD64 for PROCESSOR_ARCHITECTURE. ... It turns out that you already have the answer with the script Paul showed if you just check the value he points to rather than using the post-processing via MsgBox. ... I need further granularity in case a 64 bit operating system ...
    (microsoft.public.scripting.vbscript)
  • Re: System Environment Variables
    ... OS system variable to check which operating system the script is ... WScript.Quit'Terminate script execution ... 'This function retrieves and displays operating system information ... I think I will learn more about Windows ...
    (comp.lang.cobol)
  • Re: Help in checking the OS type...
    ... It lists me out the operating system name thanks for the same. ... I need to develop a script where in i need to first check the type ... Then the Total Space of each ...
    (perl.beginners)
  • Re: problem with logoff script
    ... the script engine as a process on the workstation and should execute cleanly ... var fso = new ActiveXObject; ... sho.popup('An error occured attempting to get the Operating System Type. ... // Retrieve the script application ...
    (microsoft.public.win2000.group_policy)