exec format error at system.diagnostics.process - linux

I have a .net core application which will unzip a file using 7zip.exe. this application is working fine with windows. once after I deployed it in docker , I am getting an error as "exec format error at system.diagnostics.process".
var processStartInfo = new ProcessStartInfo
{
FileName = sevenZPath,
Arguments = "x \"" + filePath + Path.DirectorySeparatorChar + fileName + "\" -o" + outputPath
};
var process = System.Diagnostics.Process.Start(processStartInfo);
process?.WaitForExit();
Even if I am running the exe directly from the container I am getting the same error.

Related

Azure Linux App Service with .Net Core Stack. Unable to use NodeJS

I am hosting a .NET Core Application on MS Azure (on a Linux Service Plan) and I want to run some NodeJS code in the .NET Core Application. I did this a while ago on a Windows Service Plan, there it was working. Now I am trying with a Linux Plan and it is not working.
First I was trying to use "Jering.Javascript.NodeJS" and then also "INodeServices" from Microsoft (which is obsolete). But "node" was not found. I also tried to start directly a Process (Code below), but also not working. "node" is not found.
var proc = new System.Diagnostics.Process
{
StartInfo = new System.Diagnostics.ProcessStartInfo
{
FileName = "node",
Arguments = " -v",
RedirectStandardOutput = true
}
};
result += "RUN: " + proc.StartInfo.FileName;
proc.Start();
var reader = proc.StandardOutput;
NodeJS is installed on the server and also the command works there but it seems that the .NET Core app is hosted as docker and does not have any access outside to run NodeJS. Image
I found a useful information here.
The problem is that Node is not present in the container so it is
necessary to have a script to install and start it before starting the
app itself.
Reproduceļ¼š
Here is my script:
//using System.Diagnostics;
ProcessStartInfo startinfo = new ProcessStartInfo();
startinfo.FileName = "bash";
//startinfo.FileName = "/etc/opt/nodejs/14.15.0/bin/node"; //it's no use even node package located here.
Process process = new Process();
process.StartInfo = startinfo;
process.StartInfo.UseShellExecute = false;
process.StartInfo.RedirectStandardInput = true;
process.StartInfo.RedirectStandardOutput = true;
process.Start();
//install and start nodejs
process.StandardInput.WriteLine("apt-get install curl");
process.StandardInput.WriteLine("curl -sL https://deb.nodesource.com/setup_12.x | bash");
process.StandardInput.WriteLine("apt-get install -y nodejs");
//Run "node -v"
process.StandardInput.WriteLine("node -v");
string line = string.Empty;
while (!process.StandardOutput.EndOfStream)
{
line = process.StandardOutput.ReadLine();
_logger.LogInformation(line);
}
process.WaitForExit();
return string.Empty;
It works on my .net Core app based on Linux.
I think I found a better solution ;)
In an app service you can mount a storage. In my case I mounted a storage, which contains the nodeJS lib.
Azure Portal Screenshot
Now i can execute the following code:
string result = "";
var proc = new System.Diagnostics.Process
{
StartInfo = new System.Diagnostics.ProcessStartInfo
{
FileName = "/externallibs/node/bin/node",
Arguments = " -v",
RedirectStandardOutput = true
}
};
result += "RUN: " + proc.StartInfo.FileName;
proc.Start();
var reader = proc.StandardOutput;
return result + reader.ReadToEnd();
You can create on azure portal an environment var named POST_BUILD_COMMAND with a command to fix your environment path.
Linux Service Plans runs on Oryx which is documented here
POST_BUILD_COMMAND=PATH=/usr/bin/node:$PATH

Sometimes normal conversion fails on Windows with error 1

I run ffmpeg.exe from node (spawn()) and sometimes (not random but depending on the day) it fails on Windows with error 1
I use a very basic syntax:
const outputPath = getTempFolder() + path.sep + 'video.mp4';
const command = spawn(ffmpegPath, [
'-i',
getTempFolder() + path.sep + 'video.webm',
'-y',
outputPath
]);
Any idea why this could happen and eventually how to debug it? Thanks!

Node.JS EXE Deleting executing file

I have an monitor.js file that I turned into an executable using nexe.
I want the monitor to have the ability to uninstall itself, which means delete it's own .exe file and his containing directory.
I tried : (monitorPath = monitor.exe file path, installPath = monitor.exe folder)
childProcess.exec("TIMEOUT 3 && del " + monitorPath + " && rmdir " + installPath);
setTimeout(function() {
process.exit(0);
}, 2000);
EDIT: It should run on windows, so those are all windows commands
Solved using the start command
var installPath = path.join(exePath, "..");
var monitorPath = path.join(installPath, "qqmonitor.exe");
var delCommand = 'start cmd /c "cd .. && TIMEOUT 1 && del "' + monitorPath + '" && rmdir "' + installPath + '" && exit"';
log("Uninstalling with command : '" + delCommand + "'");
childProcess.exec(delCommand, null);
setTimeout(function () {
process.exit(0);
}, 500);

sftp JSch transfer file to remote cygwin

I am trying copy files from local windows machine to remote windows machine using sftp JSch. Remote machine has cygwin, but file is not getting transferred. While doing, it is not throwing any error.
I tried with different destination path format like /cygdrive/d/ and also d://.
String destination = "/cygdrive/d/Test1";
String source = "D:\\Test";
List<String> files = NFileUtils.listFiles(source);
for (String f : files) {
String fileName = NFileUtils.getFilename(f);
try {
sftp.put(f, destination + "\\" + fileName);
} catch (Exception e) {
System.out.println(e);
}
}
sftp.put(f, destination + "\\" + fileName);
SFTP uses a file-naming model in which "/" is the directory separator character. Try using "/" as the path separator instead of "\":
sftp.put(f, destination + "/" + fileName);
If fileName contains any "\" characters, you'll need to change them as well.

Mono restart console application

I have written a console application in mono for linux.
i have to start it with
"sudo mono app.exe"
Is there some posibility to restart the app when something happens.
For examlpe I run this app on the raspberry Pi, and when the app
detects some voltage on a special IO pin the app should restart automatically.
Please help me.
You can launch a new application instance using methods in the Process class and later exit.
http://www.dotnetperls.com/process-start
On Windows you can use cmd.exe to execute the script. In this blog post the author asks cmd to wait for a while, and then delete the executable,
http://blog.pedroliska.com/2010/05/20/c-self-destruct-windows-app/
You can use the same trick to restart the executable if on Windows.
var startInfo = new ProcessStartInfo();
startInfo.FileName = "cmd.exe";
startInfo.RedirectStandardInput = true;
startInfo.UseShellExecute = false;
startInfo.CreateNoWindow = true;
var process = new Process();
process.StartInfo = startInfo;
process.Start();
// The delay is just making sure the exe to delete is done
// running.
var delayPings = 2;
var exeName = AppDomain.CurrentDomain.FriendlyName;
process.StandardInput.WriteLine("(ping -n " + delayPings + " 127.0.0.1) && (CALL " + exeName + ")");
Now for Linux, you just need to use bash (or another Shell) to replace cmd and also modify the command passed to it.

Resources