I’ve quickly searched through this site and Google, but I did not find the answer.
I started to use new Force.com CLI on Windows, but I faced with trouble that I can’t run apex code from command line (I tried Cygwin and cmd shells).
The trouble is that the CLI just do nothing. Help says that for running a code I need to type my code and just pres [Control + D], but it seems not working for me.
I tried different keys combinations based on the Wikipedia article about mapping a keyboard shortcuts on different OS as well as random pressing the most known keys combinations. Other commands work normally.
I observe the same thing. It just hangs and I have to hit CTRL-C to leave get out of it and nothing happens. Also, CTRL-Z didn’t work.
You can create a file and you can actually just pass the name of the file as a parameter to the
force apex command as that is one of the supported parameters.
If you run
force help apex you get the the usage:
For example, create a file called anonApex.txt in the directory you are in and put
System.debug('hello world'); in it.
Then, from the command line:
C:\path\to\your\dir>force apex anonApex.txt
You get something like:
Perhaps it has something to do with detecting, from the command line, an end of transmission or end of file character difference between *nix and Windows. I wouldn’t be surprised if CTRL-D worked on *nix based systems. Usually it is CTRL-Z on Windows.
I believe my guess at the this to be confirmed. I found the following issue logged against the Go Programming language:
Issue 6303: syscall: reading os.Stdin does not treat ^Z as EOF on Windows which looks a lot like what we are observing.
After reading over that issue and related discussions, I think that the handling of CTRL-Z for Windows console apps is not a high priority for the Go Programming language, so it looks like the only way to use the
force apex command from Windows is with a file input. CTRL-Z will not work unless the underlying Go Programming language changes.