>Hi, I know I can use ipconfig.exe is DOS to get my IP address, the
>situation is I need to automat this process.
I need to write a DOS program which issue a command to run IPCONFIG to
get the IP address then issue a net use command to map a drive on the
network.
You say "the IP address" like it was unique. It's not. Most systems
where you even care about IP addresses have at least two (and sometimes
hundreds per network interface), and one of them is 127.0.0.1 .
>I know you can use system
system ('command.com /c ipcoinfig.exe")
or
system ('command.com ipcoinfig.exe")
ipcoinfig.exe is limited to systems with the coin-slot attachment
on the keyboard. This can't compile due to the types of quotes
used above.
>the start the shell, but how do I capture the output from it?
Some shells allow I/O redirection, in a system-dependent manner.
Just about *ANY* command you feed to system() is system-dependent
(exception: a NULL pointer). You may need a trap and suitable bait.
I recommend you hand-type any command you intend passing to system()
to the shell used by system() and verify that it works the way
you expect before proceeding.
>after I capture the IP address
There you go with *the* IP address again. Press CTRL-ALT-DEL with
*THE* finger (hint: it's attached to *MY* hand, not yours, and
it's not long enough to reach from CTRL to DEL).
>then from the IP I can know which server
on the network I need to map to, so I can issue another
system("comman d.com net use z: \\xyzserver\mys hare mypw /User:me")
You probably don't want a literal string here, as you've indicated
that some of the content of this string is dependent on your
IP address information. What is \m inside a string? You probably
need to double up on all the backslashes inside a quoted string literal.
>to map the drive, I need to also check if the net use worked correctly.
Does "net use" return status to the shell, which might be returned
to system() (all together now:) IN A SYSTEM-DEPENDENT MANNER?
Is there a way of testing whether it worked? E.g. try to open
a file you know is supposed to exist, and if it fails, your drive mapping
may have failed.