Author Topic: How to use CMD_NULL on Windows??  (Read 5354 times)

Offline stahta01

  • Lives here!
  • ****
  • Posts: 7649
    • My Best Post
How to use CMD_NULL on Windows??
« on: June 16, 2015, 05:16:47 am »
Follow up on this old thread http://forums.codeblocks.org/index.php/topic,11278.0.html

I am looking at doing some pre and post commands.

And, I have NOT figured out how to use $(CMD_NULL) in CB in a way that does NOT cause an error

In Pre-build steps
Code
CMD /C dir > NUL

Gives this when ran
Code
Running target pre-build steps
CMD /C dir > NUL

In Pre-build steps
Code
CMD /C dir > $(CMD_NULL)

Gives this when ran
Code
Running target pre-build steps
CMD /C dir > cmd /c NUL
File Not Found


Tim S.

C Programmer working to learn more about C++ and Git.
On Windows 7 64 bit and Windows 10 64 bit.
--
When in doubt, read the CB WiKi FAQ. http://wiki.codeblocks.org

Offline stahta01

  • Lives here!
  • ****
  • Posts: 7649
    • My Best Post
Re: How to use CMD_NULL on Windows??
« Reply #1 on: June 16, 2015, 05:24:50 am »
I am thinking this line

Code
m_Macros[_T("CMD_NULL")]  = cmd + _T("NUL");

should be instead
Code
m_Macros[_T("CMD_NULL")]  = _T("NUL");

in file macrosmanager.cpp.

Edit: Added git formatted patch file.

Tim S.
« Last Edit: June 16, 2015, 06:21:55 am by stahta01 »
C Programmer working to learn more about C++ and Git.
On Windows 7 64 bit and Windows 10 64 bit.
--
When in doubt, read the CB WiKi FAQ. http://wiki.codeblocks.org

Offline stahta01

  • Lives here!
  • ****
  • Posts: 7649
    • My Best Post
Re: How to use CMD_NULL on Windows??
« Reply #2 on: June 16, 2015, 06:24:34 am »
I am thinking these two macros would be useful.

CMD_CP_UPDATE is to copy files only if file is newer.
CMD_IGNORERR is to reset the OS error value to the no error value.

I have only tested them on Windows 32 bit at this time.

I tested them using these pre build steps
Code
CMD /C dir
$(CMD_MKDIR)  "a/b/c" > $(CMD_NULL) $(CMD_IGNORERR)
$(CMD_CP_UPDATE) *.cbp a

Attached Git formatted patch.

Tim S.

C Programmer working to learn more about C++ and Git.
On Windows 7 64 bit and Windows 10 64 bit.
--
When in doubt, read the CB WiKi FAQ. http://wiki.codeblocks.org

Offline ollydbg

  • Developer
  • Lives here!
  • *****
  • Posts: 5970
  • OpenCV and Robotics
    • Chinese OpenCV forum moderator
Re: How to use CMD_NULL on Windows??
« Reply #3 on: June 16, 2015, 04:37:08 pm »
Follow up on this old thread http://forums.codeblocks.org/index.php/topic,11278.0.html

I am looking at doing some pre and post commands.

And, I have NOT figured out how to use $(CMD_NULL) in CB in a way that does NOT cause an error

In Pre-build steps
Code
CMD /C dir > NUL

Gives this when ran
Code
Running target pre-build steps
CMD /C dir > NUL

In Pre-build steps
Code
CMD /C dir > $(CMD_NULL)

Gives this when ran
Code
Running target pre-build steps
CMD /C dir > cmd /c NUL
File Not Found


Tim S.
Hi, Tim, the above code shows that "$(CMD_NULL)" should be replaced to "NUL" under Windows, not "cmd /c NUL", right?
So, this is a good contribution as I can see.

If some piece of memory should be reused, turn them to variables (or const variables).
If some piece of operations should be reused, turn them to functions.
If they happened together, then turn them to classes.

Offline stahta01

  • Lives here!
  • ****
  • Posts: 7649
    • My Best Post
Re: How to use CMD_NULL on Windows??
« Reply #4 on: June 16, 2015, 05:02:23 pm »
Follow up on this old thread http://forums.codeblocks.org/index.php/topic,11278.0.html

I am looking at doing some pre and post commands.

And, I have NOT figured out how to use $(CMD_NULL) in CB in a way that does NOT cause an error

In Pre-build steps
Code
CMD /C dir > NUL

Gives this when ran
Code
Running target pre-build steps
CMD /C dir > NUL

In Pre-build steps
Code
CMD /C dir > $(CMD_NULL)

Gives this when ran
Code
Running target pre-build steps
CMD /C dir > cmd /c NUL
File Not Found


Tim S.
Hi, Tim, the above code shows that "$(CMD_NULL)" should be replaced to "NUL" under Windows, not "cmd /c NUL", right?
So, this is a good contribution as I can see.

Correct, it is what I think it should do; in order that what it does matches what Linux does.

Edit: I am trying to figure out how to write post/pre build steps that are the same for Windows and Linux.

Tim S.
C Programmer working to learn more about C++ and Git.
On Windows 7 64 bit and Windows 10 64 bit.
--
When in doubt, read the CB WiKi FAQ. http://wiki.codeblocks.org