launch linux script from windows application

Open forum for end-user questions about Wine. Before asking questions, check out the Wiki as a first step.
Forum Rules
Locked
cmarin
Level 1
Level 1
Posts: 8
Joined: Wed Jul 30, 2008 9:21 am

launch linux script from windows application

Post by cmarin »

Hi,

We have developed a client-server application to develop and run an ERP application. The server app runs in Linux and the client app it has been developed in windows with c++, using win32 API. Now I'm trying to run it in Linux with Wine. It works fine except when i have to run some java code, in order to do that i wrote a bash script that works ok when I launch it through the command line, but when I launch it inside my windows app doesn't work.

In order to launch it from my windows application I use the _spawnlp function. The return status is -1.

There is the code:

Code: Select all

char str_aux[MAX_PATH+1];
int result = _spawnlp(_P_NOWAIT, "/home/dims/strjava","/home/dims/strjava", str_aux, NULL );
In str_aux I send the parameters that the linux script needs.
The script strjava is 'chmod a+x'.
In order to find out if the script is launched, the first thing that it does is echo the parameters to a file. It does nothing.

Somebody can give a little light to me on the subject?

Thanks.
qwertymn
Level 4
Level 4
Posts: 236
Joined: Thu Mar 27, 2008 3:42 am

Post by qwertymn »

Maybe something like the following works:

execl("/home/dims/strjava","strjava",NULL);
(on success it should not return)

However, i'm not sure how to send the parameters that the linux script needs.

(if this fails it might be better to ask this on wine-devel mailing list) Good luck
vitamin
Moderator
Moderator
Posts: 6605
Joined: Sat Feb 23, 2008 2:29 pm

Re: launch linux script from windows application

Post by vitamin »

cmarin wrote:Hi,

We have developed a client-server application to develop and run an ERP application. The server app runs in Linux and the client app it has been developed in windows with c++, using win32 API. Now I'm trying to run it in Linux with Wine. It works fine except when i have to run some java code, in order to do that i wrote a bash script that works ok when I launch it through the command line, but when I launch it inside my windows app doesn't work.

In order to launch it from my windows application I use the _spawnlp function. The return status is -1.

There is the code:

Code: Select all

char str_aux[MAX_PATH+1];
int result = _spawnlp(_P_NOWAIT, "/home/dims/strjava","/home/dims/strjava", str_aux, NULL );
In str_aux I send the parameters that the linux script needs.
The script strjava is 'chmod a+x'.
In order to find out if the script is launched, the first thing that it does is echo the parameters to a file. It does nothing.

Somebody can give a little light to me on the subject?

Thanks.
You can't run scripts that way. Only binaries. So you'll need to start "/bin/sh -c /home/dims/strjava" instead.
cmarin
Level 1
Level 1
Posts: 8
Joined: Wed Jul 30, 2008 9:21 am

Post by cmarin »

Thanks for your responses.

I tried all these possibilities unsuccessfully

Code: Select all

int result = _spawnlp(_P_NOWAIT, "/bin/sh" , "/bin/sh", "-c", "/home/dims/strjava", NULL );

int result = _spawnlp(_P_NOWAIT, "/bin/sh" , "sh", "-c", "/home/dims/strjava", NULL );

int result = _execl("/bin/sh" , "/bin/sh", "-c", "/home/dims/strjava", NULL );

int result = _execl("/bin/sh" , "sh", "-c", "/home/dims/strjava", NULL );
Any other idea?
qwertymn
Level 4
Level 4
Posts: 236
Joined: Thu Mar 27, 2008 3:42 am

Post by qwertymn »

Hi, i don't know if this is exactly the same what you try, but for me the following does work:

I created a script /tmp/script.sh with content:

konqueror www.winehq.org

Then a program test.c:

#include <windows.h>

int main()
{
execl("/bin/sh","sh","/tmp/script.sh",NULL);
}


After compiling it, and running it in wine, it seems to work just fine; konqueror is started and opens the website. Is your script very different from this simple app? (Note, as i said already, execl doesn't return, so no return value, i guess something similar can be done with _spawnvp
cmarin
Level 1
Level 1
Posts: 8
Joined: Wed Jul 30, 2008 9:21 am

Post by cmarin »

Hi,

Is very strange.

I'm using Microsoft C++.net 2003 to compile my app.

Now I have tried this:

I created a new WIN32 console app with the wizard with this very simple code:

Code: Select all

#include "stdafx.h"
#include <windows.h> 
#include <process.h>

int _tmain(int argc, _TCHAR* argv[])
{
	printf("%s", "\nHola\n");
	execl("/bin/sh", "sh", "ls", NULL); 
	return 0;
}
Neither works.

Thanks for your contributions.
qwertymn
Level 4
Level 4
Posts: 236
Joined: Thu Mar 27, 2008 3:42 am

Post by qwertymn »

but "ls" is not a script file, so that won't work anyway i guess. What happens if you replace "ls" in your code with "zcat". Then it should print something like:

Hola
gzip: compressed data not read from a terminal. Use -f to force decompression.
For help, type: gzip -h


so apparently it works ok (here at least ;))
penna

launch linux script from windows application

Post by penna »

Hi,

I do not know if this can help you, but, for sure, it helps me
starting Linux apps inside Wine.

http://wiki.jswindle.com/index.php/Adva ... _From_Wine

Regards
---------------------------------------------------------
Ulisses de Sousa Penna
Analista de TI - Banco do Brasil
Fone: +55-61-3310-6320
---------------------------------------------------------
cmarin
Level 1
Level 1
Posts: 8
Joined: Wed Jul 30, 2008 9:21 am

Post by cmarin »

Hi.

I change the "ls" by a "zcat" and the same thing, it doesn't work.

I also read the link in the post by Penna.

I have wine 1.0 running in Ubuntu 8.04

No longer I know that to change so that it works.

Regards
vitamin
Moderator
Moderator
Posts: 6605
Joined: Sat Feb 23, 2008 2:29 pm

Post by vitamin »

cmarin wrote:Hi,

Is very strange.

I'm using Microsoft C++.net 2003 to compile my app.

Now I have tried this:

I created a new WIN32 console app with the wizard with this very simple code:

Code: Select all

#include "stdafx.h"
#include <windows.h> 
#include <process.h>

int _tmain(int argc, _TCHAR* argv[])
{
	printf("%s", "\nHola\n");
	execl("/bin/sh", "sh", "ls", NULL); 
	return 0;
}
That's wrong. It should be

Code: Select all

	execl("/bin/sh", "-c", "ls", NULL); 
cmarin
Level 1
Level 1
Posts: 8
Joined: Wed Jul 30, 2008 9:21 am

Post by cmarin »

Hi,

Tthis is not problem, also I tried with "-c"

Regards
vitamin
Moderator
Moderator
Posts: 6605
Joined: Sat Feb 23, 2008 2:29 pm

Post by vitamin »

cmarin wrote:Hi,

Tthis is not problem, also I tried with "-c"

Regards
http://bugs.winehq.org/show_bug.cgi?id=14541 might have something to do with it.
qwertymn
Level 4
Level 4
Posts: 236
Joined: Thu Mar 27, 2008 3:42 am

Post by qwertymn »

i don't know any more why it doesn't work for you :(
The only thing i guess i did different is that i compiled simple sample with i386-mingw32-gcc (from mingw32) Might that make a difference? I dunno...
cmarin
Level 1
Level 1
Posts: 8
Joined: Wed Jul 30, 2008 9:21 am

Post by cmarin »

Hi,

Finally I have solved to the problem doing a compiled intermediate program with Mingw that is in charge to pick up the parameters of the application and to launch the script linux with them.

There is the code:

Code: Select all

int main(int argc, char *argv[])
{
	if (argc >= 2)
	{
		spawnlp(_P_NOWAIT, "/bin/sh","sh", "strjava", argv[0], argv[1], NULL);
	}
	return 0;
}
Thank you to all by your contributions. The forum works!
Locked