[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: one shell command doesn't return result
From: |
Eli Zaretskii |
Subject: |
Re: one shell command doesn't return result |
Date: |
Sun, 15 Jun 2008 21:22:39 +0300 |
> Date: Sun, 15 Jun 2008 16:34:16 +0200
> From: "address@hidden" <address@hidden>
>
> I would like to make a simple calculation in my makefile, but I have a
> strange problem.
> On windows, I use the DOS command "set /A 3*100+13/2", it works on a shell
> and returns "306" but not in my makefile. I have make a simple makefile to
> test it :
>
> --------------------------------------------------
> # command to make a mathematical operation
> CMD_MATH:=$(shell set /A 3*100+13/2)
> # command to list files
> CMD_FILES:=$(shell dir /b/a-d/-W)
>
> all::
> @echo CMD_MATH:$(CMD_MATH)
> @echo CMD_FILES:$(CMD_FILES)
> --------------------------------------------------
>
> It returns me :
>
> --------------------------------------------------
> CMD_MATH:
> CMD_FILES:Makefile Makefile~
> --------------------------------------------------
>
> One command returns correctly the result but not the command "set /A" which
> returns nothing.
> I have GNU Make 3.81
This is expected behavior. "set /?" has this small print among its
text:
If SET /A is executed from the command line outside of a command
script, then it displays the final value of the expression.
Note the "outside of a command script" condition: this is the cause of
your surprise. When Make uses cmd.exe as the shell, it invokes all
the commands through temporary batch files (a.k.a. command scripts);
you can see that if you invoke Make with the --debug=j switch. And
when "set /a" is invoked from a batch file, it does not print the
result.
The following trick will do what you want:
CMD_MATH:=$(shell cmd.exe /c "set /A 3*100+13/2")