1

I'm calling Microsoft's _wspawnv function, and it keeps returning -1 with errno set to 22; errno.h defines this as EINVAL. According to Microsoft's documentation for _wspawnv, this code should only be returned if the mode parameter is invalid. I've tried calling it with _P_WAIT and _P_NOWAIT in the first parameter, and both return the same error.


Edit: It's amazing how many problems can be solved by going away for a day. It didn't take me long to realize that the filename in the second parameter had quotes around it. Took them out, problem solved.

Moral of the story - don't trust the documentation to tell you everything. I didn't spend a lot of time double-checking the filename because the documentation didn't list it as a possible suspect, even though the error code implied that any parameter might be invalid.

Mark Ransom
  • 299,747
  • 42
  • 398
  • 622
  • What's the exit code that is returned if you run this program from the command line? (You should be able to use echo %ERRORLEVEL% after the command completes). – jdigital May 28 '09 at 23:45

1 Answers1

2

Oddly, the documentation also states:

If execution is allowed to continue, these functions set errno to EINVAL, and return -1. No new process is spawned.

How much of it should be trusted?

Also, it isn't supposed to return EINVAL. It sets errno to EINVAL.

sean e
  • 11,792
  • 3
  • 44
  • 56
  • Thanks for noticing that. I think I saw it earlier, and dismissed it because I knew all the conditions to be false. I also think you're right about the code being in errno instead of a return value, but I don't have the exact code in front of me right now - I'll have to check later. – Mark Ransom May 29 '09 at 00:43
  • I've accepted this answer as the most helpful, as it pointed out the obvious contradiction in the documentation. The lack of competition didn't hurt either. – Mark Ransom May 29 '09 at 18:48
  • What is the solution here? I am facing the same problem. I don't have quotes in second parameter. – Shashi Jul 06 '15 at 15:06
  • @Shashi the problem wasn't quotes in particular, it could be caused by any of the invalid filename characters. See e.g. http://stackoverflow.com/questions/1976007/what-characters-are-forbidden-in-windows-and-linux-directory-names – Mark Ransom Jul 06 '15 at 15:26