How do I take screencapture in batchmode

I have a simple project with a scene that I can run through the Unity app. I am now trying to take and save a simple screenshot in batchmode, but to no avail.

Here is the code I use:

using System.Collections.Generic;
using UnityEngine;
using System.IO;

public class TakeAShot: MonoBehaviour
{
public static void MyGameMethod()
{
string imagePath = "Assets/Resources/test.png";
ScreenCapture.CaptureScreenshot(imagePath);
}
}```

Here is the command I am running:

```/Applications/Unity/Hub/Editor/2019.4.3f1/Unity.app/Contents/MacOS/Unity -batchmode -projectPath /Users/mikemike/MyFirstGame -executeMethod TakeAShot.MyGameMethod -quit```

The command does not error out, but no screenshot is being saved.

Thanks in advance for your help

I suspect the issue here is that you are passing a relative path to CaptureScreenshot and it is being saved in an unexpected location. I would suggest something like this to save it in the application specific folder on your OS:

var folderPath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), Application.productName, "Screenshots");
ScreenCapture.CaptureScreenshot(path);

On windows, for example, it would be then saved here (generally):

C:\Users\YourUser\AppData\Roaming\YourGame\Screenshots