SharePoint stsadm.exe and the infamous "Command line error"

The SharePoint command-line utility stsadm.exe was driving me crazy for the last two days. I'm automating all kind of this from PowerShell scripts, but I got the error "Command line error" while I was absolutely sure that what I was doing was correct. I did stsadm.exe -o deletesolution foobar.wsp. And the problem was: character encoding...

First I thought it was a problem with the way I executed this command from PowerShell. When I copied over the command to a different script it worked. What!!!??? Then I copied it over to the cmd.exe shell on the command line and I got the same error.

I started searching on Google and came accross this blogpost. It said it had something to do with encoding. The blog post also pointed to this blog post where people responded in the contents with the most hillarious solutions like:

If I type STSADM.EXE it works, while STSADM.exe does not work, or that a solution file must be in the same folder as stsadm.exe. Read the comments, it is fun how far off people can get.

Another post mentioning the problem is this discussion thread.

The problem happened to be in the encoding. One way or the other it is possible to get different encodings while typing in the same command multiple times in the same cmd.exe shell. Don't ask me how.

If you have problems, type your text in an editor like Notepad++, and switch between "Encode in ANSI" and "Encode in UTF-8" (it is under the Format menu in Notepad++). You see (sometimes)the dash(-) in stsadm -o command... change from '-' to a strange little block... There is the problem. The dash is not always a dash, it is a hyphen... And stsadm then thinks that no command is specified. Remove the strange block, type a hyphen while is UTF-8 encoding, copy that and bingo!! It works.

Ok, how to repeat this:

  1. Start Notepad++, set encoding to ANSI
  2. Make sure the path to stsadm.exe is in your path environment variable (or use full path)
  3. Type stsadm -o deletesolution foobar.wsp
  4. Start cmd.exe
  5. Copy the text over and press enter: voila, Command line error.

The strange thing is that even if you remove the dash (-), and type it again, it still gives errors. I have no clue why.

This dash/hypen thing is a common problem if you search Google, for more info see for example:

Published Saturday, December 22, 2007 1:11 AM by svdoever
Filed under: , ,

Comments

# SharePoint stsadm.exe and the infamous “Command line error” · Bingo News

Pingback from  SharePoint stsadm.exe and the infamous “Command line error” · Bingo News

# kouragethekowardlydog » SharePoint stsadm.exe and the infamous "Command line error"

Pingback from  kouragethekowardlydog » SharePoint stsadm.exe and the infamous "Command line error"

Monday, December 24, 2007 2:50 AM by Martijn Zoomers

# re: SharePoint stsadm.exe and the infamous "Command line error"

I often experience the same kind of problems when copying a STSADM command from Notepad for example. When typing in the command on the prompt by hand, it works like a charm.

Sunday, February 10, 2008 12:02 PM by mal

# re: SharePoint stsadm.exe and the infamous "Command line error"

Dude thankyou. You have saved me a huge amount of time. I cannot belive this, i thought i was going mad.

Friday, May 23, 2008 8:16 AM by hpoulter

# re: SharePoint stsadm.exe and the infamous "Command line error"

I echo mal - you (and Google) saved me a jump out the window.  

Wednesday, May 28, 2008 5:52 PM by Nilang Shah

# re: SharePoint stsadm.exe and the infamous "Command line error"

gr8 Solution.

worked like a charm.

Thanks,

Nilang

Thursday, June 26, 2008 7:32 AM by Elcides

# re: SharePoint stsadm.exe and the infamous "Command line error"

Obrigado,

Esta foi difícil.

Thursday, July 17, 2008 11:13 AM by Leslie

# re: SharePoint stsadm.exe and the infamous "Command line error"

Good post. Many thanks for this. After typing the command directly instead of pasting from notepad it all works.

Leave a Comment

(required) 
(required) 
(optional)
(required)