Pingui
Pingui

Reputation: 1496

The terminal process terminated with exit code: 1

I want to use the Visual Studio Code IDE ("VSC") to develop in MQL (rather than in the native MetaEditor IDE) as described here: How to code & compile MQL5 in Visual Studio.

My question refers to the compiling process, which consists of a VSC-task that calls a PowerShell script which invokes MetaEditor.exe to perform the actual compiling.

Everything works fine when I run the PowerShell script directly (by selecting its code and hitting F8), but when I try to run it via the designated VSC-task I get the error

The terminal process terminated with exit code: 1

(before I chose PowerShell as the default shell as described in the linked description).

This is the PowerShell script (which works with F8):

#gets the File To Compile as an external parameter... Defaults to a Test file...
Param($FileToCompile = "C:\Users\Username\AppData\Roaming\MetaQuotes\Terminal\D0E8209F77C8CF37AD8BF550E51FF075\MQL5\Experts\Advisors\ExpertMACD.mq5")

#cleans the terminal screen and sets the log file name...
Clear-Host
$LogFile = $FileToCompile + ".log"
& "C:\Users\Username\AppData\Roaming\MetaQuotes\Terminal\D0E8209F77C8CF37AD8BF550E51FF075\MQL5\compile.bat" "C:\Program Files\MetaTrader 5\metaeditor64.exe" "$FileToCompile" "$LogFile" "C:\Users\Username\AppData\Roaming\MetaQuotes\Terminal\D0E8209F77C8CF37AD8BF550E51FF075\MQL5"

#before continue check if the Compile File has any spaces in it...
if ($FileToCompile.Contains(" ")) {
    "";"";
    Write-Host "ERROR!  Impossible to Compile! Your Filename or Path contains SPACES!" -ForegroundColor Red;
    "";
    Write-Host $FileToCompile -ForegroundColor Red;
    "";"";
    return;
}

#first of all, kill MT Terminal (if running)... otherwise it will not see the new compiled version of the code...
Get-Process -Name terminal64 -ErrorAction SilentlyContinue |
    Where-Object {$_.Id -gt 0} |
    Stop-Process

#fires up the Metaeditor compiler...
& "C:\Program Files\MetaTrader 5\metaeditor64.exe" /compile:"$FileToCompile" /log:"$LogFile" /inc:"C:\Users\Username\AppData\Roaming\MetaQuotes\Terminal\D0E8209F77C8CF37AD8BF550E51FF075\MQL5" | Out-Null

#get some clean real state and tells the user what is being compiled (just the file name, no path)...
"";"";"";"";""
$JustTheFileName = Split-Path $FileToCompile -Leaf
Write-Host "Compiling........: $JustTheFileName"
""

#reads the log file. Eliminates the blank lines. Skip the first line because it is useless.
$Log = Get-Content -Path $LogFile |
       Where-Object {$_ -ne ""} |
       Select-Object -Skip 1

#Green color for successful Compilation. Otherwise (error/warning), Red!
$WhichColor = "Red"
$Log | ForEach-Object {
    if ($_.Contains("0 error(s), 0 warning(s)")) {
        $WhichColor="Green"
    }
}

#runs through all the log lines...
$Log | ForEach-Object {
     #ignores the ": information: error generating code" line when ME was successful
     if (-not $_.Contains("information:")) {
          #common log line... just print it...
          Write-Host $_ -ForegroundColor $WhichColor
     }
}

#get the MT Terminal back if all went well...
if ($WhichColor -eq "Green") {
    & "c:\program files\metatrader 5\terminal64.exe"
}

and this is the VSC-task in .json-format that should call the previous PowerShell script (but ends in the abovementioned error):

{
    // See https://go.microsoft.com/fwlink/?LinkId=733558
    // for the documentation about the tasks.json format
    "version": "2.0.0",
    "tasks": [
        {
            "label": "Compile-MQL",
            "type": "shell",
            "command": "C:\\Users\\Username\\AppData\\Roaming\\MetaQuotes\\Terminal\\D0E8209F77C8CF37AD8BF550E51FF075\\MQL5\\Compile-MQL.ps1 ${file}",
            "presentation": {
                "echo": true,
                "reveal": "always",
                "focus": false,
                "panel": "shared",
                "showReuseMessage": false
            },
            "group": {
                "kind": "build",
                "isDefault": true
            }
        }
    ]
}

Can somebody please tell me how to get rid of this error?

PS: to reproduce this issue, MetaTrader (which includes the MetaEditor IDE) needs to be downloaded (for free).

Upvotes: 2

Views: 55281

Answers (5)

kodmanyagha
kodmanyagha

Reputation: 985

You can disable "show exit alert" feature in vscode. Just search this from settings window: @feature:terminal show exit and uncheck it.

enter image description here

Upvotes: 1

William Hou
William Hou

Reputation: 1781

The SOLUTION to my problem was simple: Stop the running project.

As for my case, it was my own fault, only that I did NOT know about it.

It was like this:

I was doing Node.js coding. When I tried to run "debug", I got the following error:

 process exited with code 1

which means I could never debug.

I tried a few ways I found on the Internet, but none of them worked.

Then I found that my "nodemon" automatic start function was running.

So I stopped the running server, and I tried to run the debug function again. This time it started to work.

Upvotes: 0

Dzung Tran
Dzung Tran

Reputation: 67

I had the same problem as you (I use windows 10).

Try the following:

  1. If your computer is running powershell, turn it off.
  2. Control Panel -> Programs -> Turn Windows features on or off
  3. Search Window Powershell 2.0 -> Uncheckbox -> OK
  4. Restart

enter image description here

I hope this could help you

Upvotes: 1

Arnoud Kooi
Arnoud Kooi

Reputation: 1767

I had this issue because I accidentally deleted tsconfig.json

Upvotes: 1

postanote
postanote

Reputation: 16116

The reason this works with F8 is because you are already in a PowerShell session and thus will run natively. Using your task, you are trying to run a .ps1, without starting PowerShell.

A task run, is a task run, the particulars (switches, args, etc.) of the other thing you are running in concert may have its own needs. However, your query could be potentially seen as a duplicate of this: ---

How do i configure a task to call a PowerShell script in vscode

# Accepted answer below:

{
    "version": "0.1.0",
    "command": "powershell",
    "args": [   
        "-ExecutionPolicy",
        "Unrestricted",
        "-NoProfile",
        "-File",
        "${cwd}/source/deployment/build.ps1"       
    ],
    "taskSelector": "-task ",
    "showOutput": "always",
    "tasks": [
        {
            "taskName": "build",
            "showOutput": "always",
            "isBuildCommand": true
        }
    ]
}

See also this MSDN Channel 9 video on Task Runners.

IMHO, if you have a .ps1 that already does what you want, then why call it from a task? Sure, you can but, you are already in VSC, just run your scripts from the VSCode PowerShell console terminal, simply by typing its name.

You also don't say how you have your VSCode user settings defined.

Example - what are the below set to in your use settings:

"terminal.integrated.shell.windows":
"powershell.powerShellExePath":
"shellLauncher.shells.windows": 

Update for OP

It appears you post this query twice and I responded twice.

How to configure a task to start a .ps1-script in VSC IDE (version 2.0.0)?

Of course the solution is not mine, but from the Q&A I pointed you to.

See your other post where I pointed you to the VSCode docs about configuring your user environment for what terminals are to be used.

Your error specifically means that the shell process could not be launched, again, because it can't find what it needs because of what's in / not in your VSCode use settings.

Upvotes: 1

Related Questions