-2

I want to write java code to implement this curl command:

 curl --form "file=@7_018011.gif" --form "apikey=helloworld" --form   
 "language=por" https://api.ocr.space/Parse/Image >> m.txt

where @7_018011.gif is the name of the image i want user to input to send the request to a RESTFUL service. Where can i start ?

mmm
  • 1
  • 1

1 Answers1

0

Where can i start ?

Start by reading the javadocs for Process and ProcessBuilder. Read the linked (duplicate) Q&A as well.

However, note that the >> m.txt is shell syntax, and you can't pass that as an argument if you run curl directly. In other words, some of the solutions to the linked Q&A are not directly applicable.

There are two alternatives:

  1. Run via a subshell; e.g. run this command:

      sh -c 'curl --form "file=@7_018011.gif" 
                  --form "apikey=helloworld" 
                  --form "language=por" 
                  https://api.ocr.space/Parse/Image >> m.txt'
    
  2. Implement code to write the output to "m.txt" in Java.

Stephen C
  • 698,415
  • 94
  • 811
  • 1,216