Need help with Output/ Input reading and writting exercise
How y'all doing today? I'm working on an exercise for class where i have to solve the next problem:
In this task, we must create an application that displays the multiplication table for numbers from 1 to 10. To achieve this, we will create an application (which will be the child process) that generates the multiplication table for the number it receives as input.
-The parent process will make 10 calls to the child process, passing as input the number of the table that the child must generate (1...10).
-The child process will take this number and print the corresponding multiplication table.
-The parent process will receive what the child prints and display it.
(As far as i'm concerned i can't use threads)
I'll leave the code for both parent and child (which is stored on a .jar) on a few screenshots (Padre is parent, and Hijo is child)
It is not working since it never returns the childs part.
Thx a lot!


32 Replies
⌛ This post has been reserved for your question.
Hey @MEDICINE! Please useTIP: Narrow down your issue to simple and precise questions to maximize the chance that others will reply in here./closeor theClose Postbutton above when your problem is solved. Please remember to follow the help guidelines. This post will be automatically marked as dormant after 300 minutes of inactivity.
What exactly do you mean with it not returning?
it should print:
Tabla del n:
1 * n = n
2 * n = 2n
....
10 * n = 10n
----------Proceso n finalizado----------
where n is a number from the parent class (on for loop)
printing n for n =1, n= 2.... n = 10
but it is just printing
Tabla del n:
----------Proceso n finalizado----------
It is basically not printing the text generated on child process
The same for each of the numbers?
I assume adding
System.out.flush(); at the end of the child process doesn't do anything?
btw you can configure the child process to inherit the IO of the parent processyeah, basically the parent process will create a new process on every loop where it sends a number (taken from variable i for the loop) and child will get the table for that number
imma try
idk whether you want to do that though
How do i do that? Bruh i'm just new on coding and my teacher is garbage xd
he just gives us a 300 PDF for every lesson and won't explain nothing
new ProcessBuilder(...).inheritIO().start()okay now it says that it couldnt find the .jar
Did you just add
inheritIO()?i got it on the src
yes
that's probably why
now it is launching that error, which wasn't even doing before
The
java command fails printing information that it doesn't find the JAR to stderr (not stdout)
so reading from stdout didn't show that error
The child JAR must be in the directory you are executing the parent inhold on, says exactly this:
Error: Could not find or load main class .jar
Caused by: java.lang.ClassNotFoundException: /jar
Can you show your MANIFEST.MF?
yeah
of the child preferably

Running it manually with
java -jar works?lemme try
Maybe you edited the code and made some typo so the
java -jar was replaced by java /jar?it says: Error: Unable to access jarfile Hijo.jar
hmm
imma retry just in case
okay now it doesn´t return nothing at all(but i guess it shouldn't since it just works when getting data from parent

it just stays like that
that likely means you are accessing it from the wrong directory
the program requires input
you need to enter the number after all
yeah, but it has to come from the parent for loop
if you execute it manually, you can just type the number in the console
it's just System.in after all
oh shit that is true
okay
it is working

Okay i changed this on the ProcessBuilder on parent: Process procesoHijo = new ProcessBuilder("java", "-jar", "src/Hijo.jar").inheritIO().start();
basically just the path to the .jar. Now it is not throwing errors but
the child is not returning nothing
it does if i write a number on console
but it is supposed to get its number automatically from parent's for loop
okay i got it
finally left this :
Process procesoHijo = new ProcessBuilder("java", "-jar", "src/Hijo.jar").start();
and changed the way to send the number with
BufferedWriter pos = new BufferedWriter(new OutputStreamWriter(procesoHijo.getOutputStream()));
pos.write(String.valueOf(i));
pos.newLine();
pos.flush()
now it works
thx dude
Post Closed
This post has been closed by <@440504711305625630>.