1

Topic: The turbid question about java and c ++

Good afternoon, dear gurus! I appeal to your help as the answer itself I can not find It is had: 1. java the code (ru.java.process.manager.jar) which is able to launch through Runtime.getRuntime ().exec (); certain *.exe application, for example Runtime.getRuntime ().exec ("c: \\temp \\process_manager.exe"); 2. A C/C ++ the application code process_manager.exe which is able to cause commands through system (), for example int r_1 = system ("echo 123> c: \\temp \\123.dat"); int r_2 = system ("c: \\temp \\some_script.cmd"); 3. And CMD the code some_script.cmd: echo 456> c: \\temp \\456.dat As works: 11. If to launch process_manager.exe hands in the console form both 123.dat and 456.dat As does not work: 22. If to launch process_manager.exe through ru.java.process.manager.jar forms 123.dat, BUT DOES NOT FORM 456.dat 22.1 int r_2 = system ("c: \\temp \\some_script.cmd"); returns in this case the code "1". A question: 33. How to force to work a call system ("c: \\temp \\some_script.cmd") at  process process_manager.exe from under java machines? Code samples: 44. ru.java.process.manager.jar.starter.cmd: java-jar ru.java.process.manager.jar ru.java.process.manager. MainClass 55. ru.java.process.manager.jar package ru.java.process.manager; public class MainClass {public static void main (String [] args) {try {//Runtime.getRuntime ().exec ("c: \\temp \\process_manager.exe");//} catch (Exception e) {e.printStackTrace ();}}} 66. process_manager.exe #include <cstdlib> / ** * */int main (int argc, char ** argv) {//it works and at start process_manager.exe as hands from the console//and at start process_manager.exe through java ru.java.process.manager int r_1 = system ("echo 123> c: \\temp \\123.dat");//and here it works at start process_manager.exe as hands from the console//but does not work at start process_manager.exe through java ru.java.process.manager int r_2 = system ("c: \\temp \\some_script.cmd");} 77. some_script.cmd echo 456> c: \\temp \\456.dat Thankful in advance!

2

Re: The turbid question about java and c ++

Hello, nikinikiniki, you wrote: Try so: system ("call c: \\temp \\some_script.cmd");

3

Re: The turbid question about java and c ++

Hello, c-smile, you wrote: CS> Hello, nikinikiniki, you wrote: CS> Try so: CS> CS> system ("call c: \\temp \\some_script.cmd"); CS> does not work - all tried. It is strange that at start exe from the console all works as expected.

4

Re: The turbid question about java and c ++

Led a little more experiments: #include <cstdlib> #include <fstream> #include <windows.h> / ** * */int main (int argc, char ** argv) {//std:: ofstream out ("c: \\temp \\process_manager.log");////it works and at start process_manager.exe as hands from the console//and at start process_manager.exe through java ru.java.process.manager int r_1 = system ("echo 123> c: \\temp \\123.dat"); out <<"r_1:" <<r_1 <<std:: endl;//and here it works at start process_manager.exe as hands from the console//but does not work at start process_manager.exe through java ru.java.process.manager int r_2 = system ("call c: \\temp \\some_script.cmd"); out <<"r_2:" <<r_2 <<std:: endl; {STARTUPINFO si = {0}; PROCESS_INFORMATION pi = {0};:: CreateProcess ("C: \\Windows \\System32 \\cmd.exe", "/c c: \\temp \\some_script.cmd", NULL, NULL, true, 0, NULL, NULL, &si, ); out <<"0 create process last error:" <<:: GetLastError () <<std:: endl;:: WaitForSingleObject (pi.hProcess, INFINITE); DWORD exit_code = 0;:: GetExitCodeProcess (pi.hProcess, &exit_code); out <<"0 create process exit_code:" <<exit_code <<std:: endl;:: CloseHandle (pi.hProcess);:: CloseHandle (pi.hThread);} {STARTUPINFO si = {0}; PROCESS_INFORMATION pi = {0};:: CreateProcess ("C: \\Windows \\System32 \\cmd.exe", "/c call c: \\temp \\some_script.cmd", NULL, NULL, true, 0, NULL, NULL, &si, ); out <<"1 create process last error:" <<:: GetLastError () <<std:: endl;:: WaitForSingleObject (pi.hProcess, INFINITE); DWORD exit_code = 0;:: GetExitCodeProcess (pi.hProcess, &exit_code); out <<"1 create process exit_code:" <<exit_code <<std:: endl;:: CloseHandle (pi.hProcess);:: CloseHandle (pi.hThread);} {STARTUPINFO si = {0}; PROCESS_INFORMATION pi = {0};:: CreateProcess ("c: \\temp \\some_script.cmd", "", NULL, NULL, true, 0, NULL, NULL, &si, ); out <<"2 create process last error:" <<:: GetLastError () <<std:: endl;:: WaitForSingleObject (pi.hProcess, INFINITE); DWORD exit_code = 0;:: GetExitCodeProcess (pi.hProcess, &exit_code); out <<"1 create process exit_code:" <<exit_code <<std:: endl;:: CloseHandle (pi.hProcess);:: CloseHandle (pi.hThread);}//out.flush (); out.close ();} At start exe a file from the console all is expected works: r_1: 0 r_2: 0 0 create process last error: 0 0 create process exit_code: 0 1 create process last error: 0 1 create process exit_code: 0 2 create process last error: 0 1 create process exit_code: 0 At start exe a file from java errors  (and the file c:\temp\456.dat does not form): r_1: 0 r_2: 1 0 create process last error: 0 0 create process exit_code: 1 1 create process last error: 0 1 create process exit_code: 1 2 create process last error: 0 1 create process exit_code: 1

5

Re: The turbid question about java and c ++

Hello, nikinikiniki, you wrote: N> Good afternoon, dear gurus! N> I appeal to your help as the answer itself I can not find And you  to wait command executions before to quit? Runtime.getRuntime ().exec ("c: \\temp \\process_manager.exe").waitFor ();

6

Re: The turbid question about java and c ++

By the way is still ProcessBuilder it will be possible it to you more conveniently

7

Re: The turbid question about java and c ++

Hello, kov_serg, you wrote: _> And you  to wait command executions before to quit? _> _> Runtime.getRuntime ().exec ("c: \\temp \\process_manager.exe").waitFor (); _> Tried on a miscellaneous, does not want... package ru.java.process.manager; public class MainClass {public static void main (String [] args) {try {//Runtime.getRuntime ().exec ("c: \\temp \\process_manager.exe").wait ();//ProcessBuilder pb = new ProcessBuilder ("c: \\temp \\process_manager.exe");//pb.start ();//pb.wait ();//} catch (Exception e) {e.printStackTrace ();}}}

8

Re: The turbid question about java and c ++

Hello, nikinikiniki, you wrote: Look here: https://stackoverflow.com/questions/219 … -correctly

9

Re: The turbid question about java and c ++

Hello, c-smile, you wrote: CS> Hello, nikinikiniki, you wrote: CS> Look here: CS> https://stackoverflow.com/questions/219 … -correctly is "1", therefore java recognizes that I have killed the process. Judging by return code (1) from system ("call my_cool_batch.cmd") java the machine probably considers that mine my_cool_batch.cmd  rather early... At me the situation is hardly more artful, as I launch system ("call my_cool_batch.cmd") from dll which is launched from process "process_manager.exe" which, in turn, is launched from java machines. I will look meanwhile on https://msdn.microsoft.com/en-us/librar … p/ms684880 (v=vs.85).aspx Thanks!

10

Re: The turbid question about java and c ++

Hello, nikinikiniki, you wrote: N> Hello, c-smile, you wrote: CS>> Hello, nikinikiniki, you wrote: CS>> Look here: CS>> https://stackoverflow.com/questions/219 … -correctly N> is "1", therefore java recognizes that I have killed the process. There idea that it is necessary to find in that output before asking return code.

11

Re: The turbid question about java and c ++

Hello, nikinikiniki, you wrote: N> does not work - all tried. It is strange that at start exe from the console all works as expected. And so too does not work: C:\Windows\System32\cmd.exe/c c:\temp\some_script.cmd?

12

Re: The turbid question about java and c ++

Hello, EreTIk, you wrote: ETI> Hello, nikinikiniki, you wrote: N>> does not work - all tried. It is strange that at start exe from the console all works as expected. ETI> And so too does not work: ETI> ETI> C:\Windows\System32\cmd.exe/c c:\temp\some_script.cmd ETI> ETI>? Too does not work...