How to tell from within the test script whether it was run in Postman or Newman

In the Test script, is there any way to find out whether it was run via Postman or Newman? What I am trying to do is if running via Newman then create a local output file containing result I want to output, but I also want the same script to be able to run by Postman in which case obvious we don’t want to write any local file.

So, is there any environment variable or is there a way to inspect the run command argument or whatever, to find out if it was run by Newman?

You can’t write to files directly from the tests tab. (From Postman or Newman as far as I’m aware).

It doesn’t support the fileSystems JavaScript libraries that are needed to do this.

However, when using Newman, you would just use the --reporter functionality built into the cli.

Hey welcome to community , what stops you from Passing an environment variable with your Newman command , and checking for it in script to determine whether it’s from Newman or not