none
cmd command unrecognized in windows 8 command prompt

    Question

  • I'm trying to create a txt file via command line on windows 8 using the following command in the root directory (C:):

     

    echo getmac for laptop > c:\data\laptop_mac.txt"
    cmd /c "getmac >> c:\data\laptop_mac.txt"

     

    The fist line works but the command prompt tells me following with the cmd command: 'cmd' is not recognized as an internal or external command, operable program or batch file.

    As a result the file does get created but it doesn't get my mac address like it should. I should point out that the exact same commands works under windows 7 enterprise. I used the sfc/scannow command to check for corrupt files and it did find some files. I would attach the log if I knew how to attach one. The file is very long and I don't want to post it directly in here because of that.

     

    Also, I did run this in administrator and windows 8 is updated. Finally, I noticed that the cmd command works in the system32 folder but I really don't think I should create a txt file there.

    Saturday, September 28, 2013 5:37 PM

Answers

  • C:\>cmd.exe /c getmac | find "Tcpip"

    So, what about that example in your case (with a more restrictive, more appropriate find filter if necessary)?  Now if you get cmd not found we will have less reason to guess that syntax or write permissions are a cause for a problem symptom.   ; )

     

    Were you going to reply to that idea but got distracted by the CBS.log issue?  <eg>

    Meanwhile I have thought of a simpler hypothesis.  Don't know why I didn't think of it earlier.  It fits all your facts so far.  Ockham's Razor?  ; )

    In a cmd window, enter:  set path

    If you don't have  %windir%\System32  (or its equivalent) in there it explains your symptoms.  I would be surprised to see that in an Administrator Command Prompt (aka elevated cmd window) but I suppose it might be something that an administrator might do to a standard user account if they didn't want standard users doing much with a Command Prompt.

    Then to fix it temporarily, before issuing anything that requires a path to %windir%\System32 simply set path to include that directory.   For example:

    set Path=%windir%\System32;%Path%

    Using %windir% is just a way of generalizing  C:\WINDOWS  when %SystemDrive% is not given, so enter whatever is appropriate if you don't have it either.

     

    Good luck

    Robert
    ---



    Robert Aldwinckle
    ---

    • Marked as answer by John Colgrove Wednesday, October 02, 2013 3:15 PM
    Tuesday, October 01, 2013 4:43 PM

All replies

  • On Windows 8 within c:\users\<me>\Documents\ I just successfully ran :

    cmd /c getmac >> pcmac.txt

    and it added the mac addresses to pcmac.txt, so as far as I can see that command does work. Is the example you list above 100% how you're writing it? You've got three quotation marks there, including quoting the getmac command, so if that's how you're writing it I'd guess at that being the problem.

    Saturday, September 28, 2013 6:00 PM
  • I'm trying to create a txt file via command line on windows 8 using the following command in the root directory (C:):

     

    echo getmac for laptop > c:\data\laptop_mac.txt"
    cmd /c "getmac >> c:\data\laptop_mac.txt"

     

    I suspect you may need to escape those >> output redirection characters.   Using just the command line I think you can use a caret (^) to do that.  Then your syntax for the second line would be:

    cmd.exe /c  "getmac ^>^> c:\data\laptop_mac.txt"

    FWIW I don't understand why you want the trailing double-quote on the first line?  Doesn't that just create an unusable extension?  Then your append would not be done to that file unless you added another escaped double-quote to it:

    cmd.exe /c  "getmac ^>^> c:\data\laptop_mac.txt^""

    which I suspect is not what you really want?

    In fact, it looks like you would need to do some more escaping to get that output append to work as desired.  I got up to  ^^^>^^^> before I gave up but maybe there is a syntax of escaping which will work for this.

    Why do you need to use cmd.exe /c  at all?  Aren't you already in a cmd window?  Then just enter:

    getmac >> c:\data\laptop_mac.txt^"

    with or without the escaped double-quote as required.

    However, if all you are trying to do is capture some output from getmac you could also instead pipe it to clip.exe and then paste the result into Notepad.   ; )

    getmac  |  clip

     

    HTH



    Robert Aldwinckle
    ---


    Saturday, September 28, 2013 8:42 PM
  • doesn't get my mac address like it should

    I just found out you could use WMIC to get those.  I haven't figured out yet where the Transport Name comes from.   E.g. minimally, for just the MACAddress

    wmic.exe  nic  where (MACAddress like "%:%") get MACAddress 

    Looks like Caption might be a good alternative.  Then:

    wmic.exe  nic where (MACAddress like "%:%") get MACAddress, Caption

    wmic has some switches which enable redirection to clipboard too but it can also make stuff show up in your browser which might make it more usable than appearing only in your cmd output buffer.



    Robert Aldwinckle
    ---

    Saturday, September 28, 2013 9:15 PM
  • On Windows 8 within c:\users\<me>\Documents\ I just successfully ran :

    cmd /c getmac >> pcmac.txt

    and it added the mac addresses to pcmac.txt, so as far as I can see that command does work. Is the example you list above 100% how you're writing it? You've got three quotation marks there, including quoting the getmac command, so if that's how you're writing it I'd guess at that being the problem.

    The reason I have 3 quotation marks is because that's what my instructor wrote. What confuses the living heck out of me is the fact that the exact same command with the quotation marks works just fine in windows 7 enterprise. I'm having a hard time understand why it doesn't work in windows 8. Btw I tried:

    cmd /c getmac >> pcmac.txt

    and it failed.

    Edit: My instructor thinks something may be broke with my command prompt that's why I tried sfc/scannow
    • Edited by John Colgrove Sunday, September 29, 2013 5:49 AM forgot to add something
    Sunday, September 29, 2013 5:46 AM
  • doesn't get my mac address like it should

    I just found out you could use WMIC to get those.  I haven't figured out yet where the Transport Name comes from.   E.g. minimally, for just the MACAddress

    wmic.exe  nic  where (MACAddress like "%:%") get MACAddress 

    Looks like Caption might be a good alternative.  Then:

    wmic.exe  nic where (MACAddress like "%:%") get MACAddress, Caption

    wmic has some switches which enable redirection to clipboard too but it can also make stuff show up in your browser which might make it more usable than appearing only in your cmd output buffer.



    Robert Aldwinckle
    ---

    Sorry, I should've put that this is for my windows class and the assignment requires us to create a txt file with our MAC address from command prompt. I'll ask him if there is an alternative route I can take and present that to him.

    Sunday, September 29, 2013 5:59 AM
  • The reason I have 3 quotation marks is because that's what my instructor wrote. What confuses the living heck out of me is the fact that the exact same command with the quotation marks works just fine in windows 7 enterprise. I'm having a hard time understand why it doesn't work in windows 8.


    We have seen discrepancies involving Enterprise versions before.  See if the cmd help could explain them:

    cmd  /?

    <extract  OS="W8.1 Pro">

    If /C or /K is specified, then the remainder of the command line after
    the switch is processed as a command line, where the following logic is
    used to process quote (") characters:

        1.  If all of the following conditions are met, then quote characters
            on the command line are preserved:

            - no /S switch
            - exactly two quote characters
            - no special characters between the two quote characters,
              where special is one of: &<>()@^|
            - there are one or more whitespace characters between the
              two quote characters
            - the string between the two quote characters is the name
              of an executable file.

        2.  Otherwise, old behavior is to see if the first character is
            a quote character and if so, strip the leading character and
            remove the last quote character on the command line, preserving
            any text after the last quote character.

    </extract>

    I guess that might cover my escaped double-quote requirement?

     

    Btw I tried:

    cmd /c getmac >> pcmac.txt

    and it failed.


    What was the symptom exactly and where were you when you tried this (directory-wise)?  E.g. Now I'm wondering where that cmd.exe would be running (therefore writing).  If it is at the root or somewhere else protected you might be seeing a permissions problem that way.  I would try running ProcMon to check on that possibility, as well as clarify exactly what that cmd.exe is doing.

     

    Good luck

    Robert
    ---



    Robert Aldwinckle
    ---

    Sunday, September 29, 2013 2:42 PM
  • As Robert suggested you should check where you're running this. As I mentioned before I've successfully run that command (without any quotes) from a non-elevated cmd prompt, with my own documents folder as the current folder. If you still get an error when doing the same on your machine, eg running it from your documents folder where they shouldn't be any permissions issues, then maybe it is an issue with your installation.
    Sunday, September 29, 2013 2:51 PM
  •  

    What was the symptom exactly and where were you when you tried this (directory-wise)?  E.g. Now I'm wondering where that cmd.exe would be running (therefore writing).  If it is at the root or somewhere else protected you might be seeing a permissions problem that way.  I would try running ProcMon to check on that possibility, as well as clarify exactly what that cmd.exe is doing.

     

    Good luck

    Robert
    ---



    Robert Aldwinckle
    ---


    The message was the same as before, 'cmd' is not recognized as an internal or external command, operable program or batch file. I was at my root folder but the same message popped up in the Documents folder also. Also, what's ProcMon exactly and how do I run that?
    Sunday, September 29, 2013 6:26 PM
  • The message was the same as before, 'cmd' is not recognized as an internal or external command, operable program or batch file. I was at my root folder but the same message popped up in the Documents folder also. Also, what's ProcMon exactly and how do I run that?

    I suppose it is possible that you don't have authority to use cmd.exe.   Or you could add the extension for it, in case that's the issue.   But you said you were already in a cmd.exe window?  Which one?  The one for standard user or the Administrator Command Prompt?  I was guessing that your symptom was some kind of parsing error but maybe it is an execution thing.  Then again, ProcMon would help expose that.  Showing that might be as simple as using a filter (Ctrl-L) with  Result Is Access Denied

    ProcMon is short for ProcMon.exe the executable for Process Explorer by SysInternals, available on TechNet.  However, if you don't have enough initiative to do a web search for it you may not want to try using it either.   ; }



    Robert Aldwinckle
    ---

    Sunday, September 29, 2013 7:00 PM
  • I suppose it is possible that you don't have authority to use cmd.exe.   Or you could add the extension for it, in case that's the issue.   But you said you were already in a cmd.exe window?  Which one?  The one for standard user or the Administrator Command Prompt?  I was guessing that your symptom was some kind of parsing error but maybe it is an execution thing.  Then again, ProcMon would help expose that.  Showing that might be as simple as using a filter (Ctrl-L) with  Result Is Access Denied

    ProcMon is short for ProcMon.exe the executable for Process Explorer by SysInternals, available on TechNet.  However, if you don't have enough initiative to do a web search for it you may not want to try using it either.   ; }



    Robert Aldwinckle
    ---

    Ha Ha, very funny. As sarcastic as I am, you think I would be used to recieving it after a while. lol!

    Silliness aside, I downloaded and ran ProcMon but the first time I applied the filters I got a blue screen. Second time it worked but the only access denied it found was for Pokki Server, over 2000 of them to be more accurate.

    Sunday, September 29, 2013 11:11 PM
  •  the only access denied it found was for Pokki Server

    Then you will have to find a better hypothesis to test.  What about filtering on your getmac  term in your Command Line?   If you still have access to W7 you could do the same trace with it and then have two traces you could filter and compare for their essential differences.  If you save a ProcMon trace with its .pml extension you can later open that in its own window which allows them to be compared side by side. 

    Another thing that I would do is put an escaped &pause  at the end of your command line...  Hmm... that's not working either.  More escape problems with it.   E.g. I tried

    C:\>cmd.exe /c getmac >>pcmac.txt&pause
    Press any key to continue . . .

    which at least proves I had the right syntax for doing a pause in the cmd window.

    But then both

    C:\>cmd.exe /c getmac >>pcmac.txt^&pause

    and

    C:\>cmd.exe /c getmac >>pcmac.txt^^^&pause

    resulted in unexpected output, e.g. as seen by a dir *.txt

    Oops.  Since I was expecting all that stuff to be processed by the internal cmd.exe I should have been quoting it and that shows what is really going on.  The output filter is always local to the original cmd window.  It still demonstrates that if I wanted to do that I would have to find a different way to get those characters into that other process but now it doesn't really matter any more.  E.g. this cmd pipeline I think is clearer:

    C:\>cmd.exe /c getmac | find "Tcpip"

    So, what about that example in your case (with a more restrictive, more appropriate find filter if necessary)?  Now if you get cmd not found we will have less reason to guess that syntax or write permissions are a cause for a problem symptom.   ; )

     
    HTH



    Robert Aldwinckle
    ---

    Monday, September 30, 2013 4:07 PM
  • C:\>cmd.exe /c getmac | find "Tcpip"

    So, what about that example in your case (with a more restrictive, more appropriate find filter if necessary)?  Now if you get cmd not found we will have less reason to guess that syntax or write permissions are a cause for a problem symptom.   ; )

     
    HTH



    Robert Aldwinckle
    ---

    I still think my error is related to sfc/scannow finding errors but was unable to fix them. I'm going to post the CBS.log it generated. I figured I would try at the least. Warning it's a long file.

    Edit: Nevermind the file was too long.

    Tuesday, October 01, 2013 3:43 AM
  • C:\>cmd.exe /c getmac | find "Tcpip"

    So, what about that example in your case (with a more restrictive, more appropriate find filter if necessary)?  Now if you get cmd not found we will have less reason to guess that syntax or write permissions are a cause for a problem symptom.   ; )

     

    Were you going to reply to that idea but got distracted by the CBS.log issue?  <eg>

    Meanwhile I have thought of a simpler hypothesis.  Don't know why I didn't think of it earlier.  It fits all your facts so far.  Ockham's Razor?  ; )

    In a cmd window, enter:  set path

    If you don't have  %windir%\System32  (or its equivalent) in there it explains your symptoms.  I would be surprised to see that in an Administrator Command Prompt (aka elevated cmd window) but I suppose it might be something that an administrator might do to a standard user account if they didn't want standard users doing much with a Command Prompt.

    Then to fix it temporarily, before issuing anything that requires a path to %windir%\System32 simply set path to include that directory.   For example:

    set Path=%windir%\System32;%Path%

    Using %windir% is just a way of generalizing  C:\WINDOWS  when %SystemDrive% is not given, so enter whatever is appropriate if you don't have it either.

     

    Good luck

    Robert
    ---



    Robert Aldwinckle
    ---

    • Marked as answer by John Colgrove Wednesday, October 02, 2013 3:15 PM
    Tuesday, October 01, 2013 4:43 PM
  • In a cmd window, enter:  set path

    If you don't have  %windir%\System32  (or its equivalent) in there it explains your symptoms.  I would be surprised to see that in an Administrator Command Prompt (aka elevated cmd window) but I suppose it might be something that an administrator might do to a standard user account if they didn't want standard users doing much with a Command Prompt.

    Then to fix it temporarily, before issuing anything that requires a path to %windir%\System32 simply set path to include that directory.   For example:

    set Path=%windir%\System32;%Path%

    Using %windir% is just a way of generalizing  C:\WINDOWS  when %SystemDrive% is not given, so enter whatever is appropriate if you don't have it either.


    I don't believe it, that seems to have fixed the issue! I think my eyes are playing tricks on me. Ha, Ha! What a relief.
    Wednesday, October 02, 2013 3:15 PM
  • There is a weirdness where cmd.exe run as administrator does not have same behavior as Command Prompt (Admin).  Many commands seem to disappear which show up in the "cmd" window as a standard user, but not in the "Administrator: cmd" window.  We saw this trying to run dfsutil in a command window.  It didn't even list out with the dir command in the "Administrator: cmd" window.  But opening with Command Prompt (Admin) menu item then dfsutil appeared.

    Perhaps this bug also tripped you up?

    Wednesday, January 08, 2014 6:27 PM