terraform init - process exception : No such file or directory
Manikandan-Apptivo opened this issue · comments
I try to run system commands on Mac flutter app, when run on android studio it work fine but when I run the project on xcode to debug or build a release app (using flutter build macos) and open, its showing process exception : No such file or directory.
I want to execute terraform script from flutter mac app, its working fine in android studio, always getting error from the xcode or release build. Could you please help and resolve this issue ASAP?
Hard to say what is going wrong here without knowing your environment (is the executable in your path) and whether you check the sandbox settings for MacOS.
What you can try:
- add print statements to confirm where the issue happens catch and print the exception
- print and check the
ShellEnvironment()
path variable - try another simple command such as
ls
- Use
dart:io
Process (process_run is just a wrapper on top of it)
downloadPath -> gave the download path
var shell = Shell(throwOnError: true, workingDirectory: downloadPath);
var res = await shell.run('''
terraform init
#terraform plan
#terraform apply -input=false -auto-approve
''');
output
Initializing the backend...
Initializing provider plugins...
- Reusing previous version of hashicorp/google from the dependency lock file
- Reusing previous version of hashicorp/vsphere from the dependency lock file
- Using previously-installed hashicorp/google v4.6.0
- Using previously-installed hashicorp/vsphere v2.0.2
Terraform has been successfully initialized!
Getting output from executing that above code from Android studio, but facing issue in Xcode or release build
shellexception(terraform init, error:processexception: no such file or directory
command:terraform init, workingdirectory:/users/name/downloads)
Release.entitlements
sandbox settings - already set false
com.apple.security.app-sandbox(Good if you can use triple ticks to format code and console output)
Regarding the exception, maybe terraform is not your path (try which('terraform') or the working directory does not exist (try replacing the comand terraform init by ls
). You should then try dart:io if you think something is going wrong elsewhere as I don't know what to try then.
Hi Alex,
Thanks for your answer.
terraform added in downloads folder and able to get the result from terminal.
In release or xcode only getting no such file or directory error.
issue with different environment path in android studio, xcode and release build.
I have checked this below references but still did not get solution. (Handled the crash only issue in environment)
Release app:
"PATH": "/usr/bin:/bin:/usr/sbin:/sbin"
If the path is fine then it will execute the terraform commands in the flutter mac app.
Could you help me, how to resolve this path issue?
You can modify the path used by the shell using something like this below. If needed ask the user for the absolute location.
import 'package:process_run/shell.dart';
Future<void> main() async {
// Create a new environment
var env = ShellEnvironment();
// Add absolute path to terraform
env.paths.add('example/my/terraform/path');
// Create shell in environment
var shell = Shell(environment: env);
// Run!
await shell.run('terraform init');
}
Hi Alex,
Now working fine.
Thank you very much.
let me close this ticket.
Hi guys sorry to open this again but I'm trying to understand what's happening here since I have the same problem
Why is that in debug or profile modes the commands are found but in release they don't? Shouldn't they work the same?
The command should indeed work the same in debug and release. The issue is that the environment is different. You can try the following:
print(Platform.environment['PATH']);
If you try in debug from the IDE (which adds some paths), in release from the command line or from an icon, you'll see that its value is different. If you added some path in .zshrc or .bashrc they are sometimes not picked up depending on how you launch your application.
So if a path is not available in release, unless you use an absolute path, the executable might not be found. I show above how to modify the env paths from within the application.