37

I am using a makefile in windows to push some files on a Unix server (here a text file "blob.txt" in the same folder of my makefile). My makefile script is:

setup:
        pscp blob.txt username@hostname:/folder/

I start a command prompt, go in the folder where blob.txt and the makefile are present and type:

make setup

Which results in:

pscp blob.txt username@hostname:/folder/
process_begin: CreateProcess(NULL, pscp blob.txt username@hostname:/folder/, ...) failed.
make (e=2): The system cannot find the file specified.
make: *** [setup] Error 2

In a #fail ... whereas if I enter directly the command in the command prompt:

pscp blob.txt username@hostname:/folder/

It works ... I really wonder why.

Colonel Beauvel
  • 30,423
  • 11
  • 47
  • 87
  • This just started happening for me as well. The make process can no longer "see" certain files on my system. I've installed GNU make with Chocolatey and it has worked flawlessly for years. All of a sudden today, files such as bash.exe and wsl.exe are hidden from the make process. – Andrew T Finnell May 31 '20 at 19:47

10 Answers10

22

The error

process_begin: CreateProcess(NULL, pscp blob.txt username@hostname:/folder/, ...) failed.
make (e=2): The system cannot find the file specified.

is almost certainly complaining that Windows cannot find pscp.

This is almost certainly because the value of %PATH% (or whatever) is different when make spawns a shell/console then when you have it open manually.

Compare the values to confirm that. Then either use the full path to pscp in the makefile recipe or ensure that the value of PATH is set correctly for make's usage.

Etan Reisner
  • 77,877
  • 8
  • 106
  • 148
  • arf I am sorry but actually it does not solve the error ... I created a command `@echo $(PATH)` in my makefile and it contains the path of the folder where pscp lies ... – Colonel Beauvel Nov 12 '15 at 16:01
  • 2
    `@echo $(PATH)` is expanding the value of the make `PATH` variable. Try using the shell path variable instead. `@echo $$PATH` or `@echo %PATH%` or whatever. – Etan Reisner Nov 12 '15 at 16:06
  • 2
    For me the problem was that I was using PowerShell instead of git terminal. – Adrian Jan 20 '22 at 06:27
20

I didn't want to remove GIT's bin folder from the PATH variable (I am using a Windows machine), as I use it quite often. So I looked for a workaround, and here it is:

Add the <git-installation-directory>/usr/bin directory to your PATH variable too. This basically adds the rest of the linux-like commands that come with the "GIT bash" to your environment. After applying this, my makefiles ran normally again. :)

If you are curious about what shell is being invoked by make, just add $(info $(SHELL)) at the beginning of your makefile. The path/name of the shell being invoked is printed to the console as soon as you run make.

Pang
  • 9,564
  • 146
  • 81
  • 122
Ricardo Alejos
  • 402
  • 4
  • 9
  • 4
    I know I'm super late to the party, but I have to say that Ricardo Alejos' answer in addition to Etan Reisner's is a great solution, if not the best solution here. This is because if you are using bash.exe or some version of bash through git's stuff, you really should be keeping all of those programs (at least the bin) in the PATH environment variable. I have not lost any functionality with any of the stuff I do between Mac, Linux (debian distro), and windows 10. – Matt Bailey Oct 16 '19 at 02:42
15

I know this is an old question that has been answered, but thought I'd and my experiences for anyone still running into this. I was getting the same cryptic error Colonel Beauvel (though with the windows MOVE command, not pscp):

process_begin: CreateProcess(NULL, move /y foo\bar.c .\baz.c, ...) failed.
make (e=2): The system cannot find the file specified.

Our CI was running the same Makefile and working perfectly. Turns out CI was using mingw32-make and I was using GNU make. Uninstalling GNU make (which got installed as part of an unrelated bulk package) and aliasing mingw32-make to 'make' works perfectly.

tkennon
  • 153
  • 1
  • 4
10

@user3869623's solution works for me. I'd like to share some details of mine to complete the picture.

My makefile contains below target:

clean:
    @echo '$(OS)'
ifeq ($(OS),Windows_NT)
    del /s *.o *.d *.elf *.map *.log
endif

When I run make clean, I see this error:

enter image description here

Since it says something went wrong with echo, so I change my makefile target to below:

clean:

ifeq ($(OS),Windows_NT)
    del /s *.o *.d *.elf *.map *.log
endif

This time, make clean gives me this error:

enter image description here

I am surprised to see bash here since I am working in Windows command line.

Then I checked my %PATH%, I see this entry:

C:\DevTools\Git\bin

There's a bash.exe and sh.exe in that path. So I removed this entry, and it works fine now.

BUT I STILL DON'T KNOW WHY BASH GET INTO THIS???

ADD 1

As to why the C:\DevTools\Git\bin shows up in my %PATH%, because I am using Sublime and it always asks me for the Git binaries:

enter image description here

smwikipedia
  • 61,609
  • 92
  • 309
  • 482
  • Some versions of `make` looks at your `SHELL` variable to decide which shell to run. Others probably have a `sh`-compatible shell hardcoded in order to avoid having Makefiles break for users with funny nonstandard shells. For the record, which `make` are you running? – tripleee Aug 23 '16 at 03:49
  • @tripleee Thanks for your comment. I am using `GNU make 3.81.2520.1772` for windows. – smwikipedia Aug 23 '16 at 05:29
  • 1
    Damn clever mistake. Dude, you are the best, thanks! – Никитос Jun 05 '23 at 07:37
9

In my case, I had git\bin in my %PATH% which contains bash.exe and sh.exe.
Removing %GIT_HOME%\bin from the PATH worked for me.

Pang
  • 9,564
  • 146
  • 81
  • 122
user3869623
  • 2,363
  • 2
  • 15
  • 19
5

To build on user3869623's response:

In my case I had git\bin in my %PATH% which contains bash.exe and sh.exe. Removing %GIT_HOME%\bin from the PATH worked for me.

While this recommendation may allow make to run, it will likely cause issues for git, especially if the makefile is installing software from a git repository.

A better solution is to simply change %GIT_HOME%\bin to %GIT_HOME%\cmd.

user16217248
  • 3,119
  • 19
  • 19
  • 37
jgrant
  • 1,273
  • 1
  • 14
  • 22
1

I'm on windows.
By explicitly setting my compiler to gcc (instead of cl?) it solved my problem.

CC = gcc

I hope some people more knowledgeable than me could explain why changing the compiler would impact the makefile parsing.

gberth
  • 467
  • 5
  • 13
0

For those who tried removing the git bin folder from PATH and it didn't work for them, search your PATH variables for any paths containing bash.exe.

In my case I found a variable linking to cygwin bin folder C:\cygwin64\bin, removed it and it worked.

0

I had the same issue, and this thread really helped me solve it. In my case, it was a conflict between make and the sh.exe that was visible through my path, due to both git and mingw64. To fix my issue, without breaking Git, I added these lines to the top of my batch file that calls make:

set path=%path:git\bin=;%
set path=%path:mingw64\bin=;%
set path=%path:usr\bin=;%

This hides the extra sh.exe instances from make for that instance only.

Pang
  • 9,564
  • 146
  • 81
  • 122
MAF
  • 59
  • 3
0

I ran into this problem recently and this question was one of the top hits for my searches.

None of the other answers here helped me. The fix, for me, was to put the binary name in quotes:

setup:
        "pscp" blob.txt username@hostname:/folder/
        -"pscp" blob.txt username@hostname:/folder/ # Failure is OK, `-` in front
Cameron Tacklind
  • 5,764
  • 1
  • 36
  • 45