Environment variables inside the system call 
Author Message
 Environment variables inside the system call

Hello all,

A small program (for DOS versions of AWK)
BEGIN {
  res = system("echo. > %TMP%\\a.txt")
  print res

Quote:
}

With mawk 1.1.3LMDOS Jan 1993, Copyright (C) Michael D. Brennan, this
seems to work.  0 is printed as a result, and the file exists in the
expected place.

With GNU Awk 3.0.3, I get:
----
Cannot redirect output: No such file or directory (ENOENT)
255
----

With MKS Awk (Copyright 1985, 1991 by Mortice Kern Systems Inc), the
result is:
----
File creation error
0
----

Now I could contruct the command line using ENVIRON["TMP"], which is
certainly the more portable answer.

Just curious about how the system command works / supposed to work,
once the string is handed over to the operating system.

Thanks in advance,
--
Steve



Thu, 18 Jul 2002 03:00:00 GMT  
 Environment variables inside the system call

...

Quote:
>BEGIN {
>  res = system("echo. > %TMP%\\a.txt")
>  print res
>}
...
>With GNU Awk 3.0.3, I get:
>----
>Cannot redirect output: No such file or directory (ENOENT)
>255
>----

Works for me under gawk 3.0.3

Quote:
>With MKS Awk (Copyright 1985, 1991 by Mortice Kern Systems Inc), the
>result is:
>----
>File creation error
>0
>----

Are you running MKS awk from the MKS shell? Or is the SHELL environment
variable set to the MKS shell in console windows (NT) or DOS prompts (95/98)?
If either are true, MKS awk will use its own shell rather than CMD.EXE or
COMMAND.COM, and %TMP% would be interpretted as literal text, hence, a literal
subdirectory under the current working directory.

Quote:
>Now I could contruct the command line using ENVIRON["TMP"], which is
>certainly the more portable answer.

Yep, that'd be the better approach.


Thu, 18 Jul 2002 03:00:00 GMT  
 
 [ 2 post ] 

 Relevant Pages 

1. Passing an environment variable to a system call within awk

2. (UNIX) Environment variables and 'system'

3. reading system environment variables

4. Shell environment for system() call

5. problems with shell environment in os.system calls

6. EQUIVALENCE(variable inside module, variable outside module) ????

7. variable inside variable

8. Pass Variable into system() call, How to

9. capturing a call system() output into a variable

10. Changing environment variables into python variables

11. Setting an environment inside an application Tcl interpreter

12. system calls - file system structure

 

 
Powered by phpBB® Forum Software