Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

why c# console command not running on java?

Tags:

java

c#

Can anyone tell me why this c# console command not running on Java?

I've made a C# console program as given below:

using System;
using System.IO;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Drawing;
namespace face
{
    class Program
    {
        public static void Main(string[] args)
        {
            String path = args[0];
            byte[] imageBytes = File.ReadAllBytes(path);
            MemoryStream ms = new MemoryStream(imageBytes, 0, imageBytes.Length);
            // Convert byte[] to Image
            ms.Write(imageBytes, 0, imageBytes.Length);
            Image image = Image.FromStream(ms, true);
            Bitmap S1 = new Bitmap(image);
            Console.WriteLine(S1.GetPixel(2, 10));
        }
    }
}

When I run Program.exe image.jpg, I get:

Color [A=255, R=128, G=32, B=128]

Then I created a simple Java application to run the Program.exe executable:

class project 
{   
 public static void main(String[] args)
 {
    String comman="C:\\WINXP\\system32\\Program.exe Sunset.jpg";
    try 
    {
     Process process = Runtime.getRuntime().exec(comman);
     System.out.println(process.getOutputStream());
    } catch (Exception e) 
         {e.printStackTrace(System.err);}
 }
}

When I try to run the Java application, I get the following error:

Program.exe has encountered a problem and needs to close. We are sorry for the inconvenience.


1 Answers

You probably want to change

String comman = "C:\\WINXP\\system32\\Program.exe Sunset.jpg";

to

String[] comman = { "C:\\WINXP\\system32\\Program.exe", "Sunset.jpg" };
like image 98
aioobe Avatar answered May 15 '26 10:05

aioobe



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!