×

Discussion Board

Results 1 to 10 of 10
  1. #1
    Registered User
    Join Date
    Sep 2013
    Posts
    24

    How to Send Cosole Exe in background and close it.

    Hi

    Using following code I am able to launch Console application from GUI Application, but not able to send it in background and to close console exe from GUI Application.

    Code:
                           //For send App in Background
    			const TUid KUidmyConsoleApp =
    			{
    					0xEC485AB3
    			};
    			RWsSession iSession ;	 
    			User::LeaveIfError( iSession.Connect() ) ; 
    			RWindowGroup iWindowGroup( iSession ) ; 
    			TApaTaskList iTaskList( iSession ) ; 
    						
    			//Working Code for Launch Console Exe
    			TThreadId app_threadid;
    			CApaCommandLine* cmdLine; 
    			cmdLine=CApaCommandLine::NewLC();
    			//cmdLine->SetExecutableNameL(_L("rtpexample.exe"));
    			cmdLine->SetExecutableNameL(_L("TestExe.exe"));
    			cmdLine->SetCommandL( EApaCommandRun );
    			RApaLsSession ls;
    			User::LeaveIfError(ls.Connect());
    			TInt err=ls.StartApp(*cmdLine,app_threadid);
    			ls.Close();
    			CleanupStack::PopAndDestroy(); // cmdLine
    			
    			//TApaTask iCurrentTask = iTaskList.FindByPos( 0 ) ;
    			TApaTask iCurrentTask = iTaskList.FindApp(KUidmyConsoleApp);
    			TInt iWindowId = iCurrentTask.WgId() ; 
    			iCurrentTask.SetWgId( iWindowId ) ; 
    			iCurrentTask.SendToBackground() ; 
    			iWindowGroup.Close() ; 
    			iSession.Close();
    Code:
                            //Close Console EXE
                            TFindProcess processFinder(_L("TestExe.exe*"));
    			TFullName result;
    			RProcess processHandle;
    			while ( processFinder.Next(result) == KErrNone) 
    				{
    			   User::LeaveIfError(processHandle.Open ( result, EOwnerThread));
    			   processHandle.Kill(KErrNone);
    			   processHandle.Close();
    				}
    Console EXE Code

    Code:
    /*
     ============================================================================
     Name		: TestExe.cpp
     Author	  : Taruna
     Copyright   : Your copyright notice
     Description : Exe source file
     ============================================================================
     */
    
    //  Include Files  
    
    #include "TestExe.h"
    #include <e32base.h>
    #include <e32std.h>
    #include <e32cons.h>			// Console
    
    //  Constants
    
    _LIT(KTextConsoleTitle, "Console");
    _LIT(KTextFailed, " failed, leave code = %d");
    _LIT(KTextPressAnyKey, " [press any key]\n");
    
    //  Global Variables
    
    LOCAL_D CConsoleBase* console; // write all messages to this
    
    
    //  Local Functions
    
    LOCAL_C void MainL()
    	{
    	//
    	// add your program code here, example code below
    	//
    	console->Write(_L("Hello, world!\n"));
    	while(1)
    		{
    		console->Write(_L("Hello, world!\n"));
    		}
    	}
    
    LOCAL_C void DoStartL()
    	{
    	// Create active scheduler (to run active objects)
    	CActiveScheduler* scheduler = new (ELeave) CActiveScheduler();
    	CleanupStack::PushL(scheduler);
    	CActiveScheduler::Install(scheduler);
    
    	MainL();
    
    	// Delete active scheduler
    	CleanupStack::PopAndDestroy(scheduler);
    	}
    
    //  Global Functions
    
    GLDEF_C TInt E32Main()
    	{
    	// Create cleanup stack
    	__UHEAP_MARK;
    	CTrapCleanup* cleanup = CTrapCleanup::New();
    
    	// Create output console
    	TRAPD(createError, console = Console::NewL(KTextConsoleTitle, TSize(
    			KConsFullScreen, KConsFullScreen)));
    	if (createError)
    		{
    		delete cleanup;
    		return createError;
    		}
    	
    	//MainL();
    	//console->Getch();
    	
    	// Run application code inside TRAP harness, wait keypress when terminated
    	TRAPD(mainError, DoStartL());
    	if (mainError)
    		console->Printf(KTextFailed, mainError);
    	console->Printf(KTextPressAnyKey);
    	console->Getch();
    
    	delete console;
    	delete cleanup;
    	__UHEAP_MARKEND;
    	return KErrNone;
    	}

  2. #2
    Nokia Developer Moderator
    Join Date
    Mar 2003
    Location
    Lempäälä/Finland
    Posts
    29,165

    Re: How to Send Cosole Exe in background and close it.

    if the console application is supposed to be used in background without UI, I would suggest you woul not implement any UIs with it in first place.

    Then you could actually use the Symbian client-server architecture, and get the communications between apps better as well.

    In case you want to communicate with the current version of the console app you have, I would suggest implementing the communications with RProperty API, then you could simply listen commands from the UI app in your console, and do the exit etc. when requested.
    Last edited by symbianyucca; 2013-11-14 at 09:04.

  3. #3
    Nokia Developer Moderator
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    28,750

    Re: How to Send Cosole Exe in background and close it.

    If you have a console object (CConsoleBase), you can try simply deleting it in order to make the code continue running in the background. Of course the IPC mechanisms listed by Jukka are still necessary.

  4. #4
    Registered User
    Join Date
    Sep 2013
    Posts
    24

    Re: How to Send Cosole Exe in background and close it.

    Quote Originally Posted by symbianyucca View Post
    if the console application is supposed to be used in background without UI, I would suggest you woul not implement any UIs with it in first place.

    Then you could actually use the Symbian client-server architecture, and get the communications between apps better as well.

    In case you want to communicate with the current version of the console app you have, I would suggest implementing the communications with RProperty API, then you could simply listen commands from the UI app in your console, and do the exit etc. when requested.
    Hi

    Thanks for help

    I remove Console class instance and PrintF line and now I able to kill the application from GUI application.

    But I don't understand other concept which you wrote.

  5. #5
    Nokia Developer Moderator
    Join Date
    Mar 2003
    Location
    Lempäälä/Finland
    Posts
    29,165

    Re: How to Send Cosole Exe in background and close it.

    Basically if you try killing a task, you would require SwEvent capability, also when something fails, you should always check the error code for the crash

    For RProperty, you could start with this article: http://developer.nokia.com/Community...or_subscribing

    also there are other articles on IPC in our wiki, so you might want to browse around a bit in there.

  6. #6
    Registered User
    Join Date
    Sep 2013
    Posts
    24

    Re: How to Send Cosole Exe in background and close it.

    Quote Originally Posted by symbianyucca View Post
    Basically if you try killing a task, you would require SwEvent capability, also when something fails, you should always check the error code for the crash

    For RProperty, you could start with this article: http://developer.nokia.com/Community...or_subscribing

    also there are other articles on IPC in our wiki, so you might want to browse around a bit in there.
    Hi

    I make OpenC EXE file of UDP Server for send commands and receive response, and calling this EXE from GUI Application.
    But For send request and receive response data from background EXE to GUI, I try to implementing the communications with RProperty API.

    I make one Sample GUI and Console EXE as per article which you described in following post no:4
    And In ExampleProperties.h file const TUid KExampleProperty = {0xE28ADD86}; I give my Console EXE UID.

    I write following code in my AppUi::ConstructL() method:
    After I build Console Exe and run GUI App give me Error "Unable to execute file for security reason"
    Please can you say that how I use this code?

    Code:
    TInt ret=RProperty::Define(KExampleProperty,EIntProperty,RProperty::EInt);
    if (ret != KErrAlreadyExists)
      {      
      User::LeaveIfError(ret);
      }
     
    ret= RProperty::Define(KExampleProperty,EStrProperty,RProperty::EByteArray,KMaxStrLen);
    if (ret != KErrAlreadyExists)
      {     
      User::LeaveIfError(ret);
      }

  7. #7
    Nokia Developer Moderator
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    28,750

    Re: How to Send Cosole Exe in background and close it.

    If you search for Unable to execute file for security reason site:developer.nokia.com with Google, you will certainly find some related discussions.
    As far as I remember, you should check platform security topics, like the UID-s and capabilities of the .exe and .dll files you have. (Do you have .dll-s? In that case note that the .dll-s need at least the same capabilities as the .exe file using them has)

  8. #8
    Registered User
    Join Date
    Sep 2013
    Posts
    24

    Re: How to Send Cosole Exe in background and close it.

    Hi

    I am not use any DLL I make only one GUI app and one Console EXE for see how to use RProperty as per link: http://developer.nokia.com/Community...for_publishing.

    GUI app and Console EXE both have same capability LocalServices ReadUserData

    I getting Error "Unable to execute file for security reason (-46)" when execute following code from GUI application.

    Code:
    //Define RProperty
    	TInt ret=RProperty::Define(KExampleProperty,EIntProperty,RProperty::EInt);
    	if (ret != KErrAlreadyExists)
    	  {      
    	  User::LeaveIfError(ret);
    	  }
    	 
    	ret= RProperty::Define(KExampleProperty,EStrProperty,RProperty::EByteArray,KMaxStrLen);
    	if (ret != KErrAlreadyExists)
    	  {     
    	  User::LeaveIfError(ret);
    	  }

  9. #9
    Nokia Developer Moderator
    Join Date
    Mar 2003
    Location
    Lempäälä/Finland
    Posts
    29,165

    Re: How to Send Cosole Exe in background and close it.

    at least You should not try defining the same property twice with different types, so I suppose you could do with the EIntProperty type property, and remove the codes for the string type. see whether that helps. You could always check the SDK dAPI docs for capabilities required by the API.

  10. #10
    Nokia Developer Moderator
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    28,750

    Re: How to Send Cosole Exe in background and close it.

    -46 is mostly about missing capabilities. There may be some documentations which do not mention it, but RProperty::Define probably requires WriteDeviceData capability. EDIT2: it requires for the protected range (UID-s below some 0x2...).
    Note that if you check these things in the emulator, the logfile (http://developer.nokia.com/Community/Wiki/Epocwind.out) tells if there is a capability issue, search for platsec warning-s in it.
    EDIT1: category should be your own UID3 (or SID) if you are working with 0xE UID-s. (EDIT2: then you may succeed without WriteDeviceData)
    Last edited by wizard_hu_; 2013-11-15 at 13:34.

Similar Threads

  1. How Can Send the Exe in the background
    By purnima.attarsingh in forum Symbian
    Replies: 9
    Last Post: 2009-10-15, 13:48
  2. Nokia N91, how to close the music application in the background?
    By goodluck_975 in forum General Development Questions
    Replies: 3
    Last Post: 2007-03-08, 14:48
  3. Background SMS Send s60 3rd Ed
    By jamespoh in forum Symbian Tools & SDKs
    Replies: 9
    Last Post: 2007-03-05, 06:58
  4. Replies: 3
    Last Post: 2006-11-09, 05:36
  5. close a background app
    By billqu in forum Symbian
    Replies: 1
    Last Post: 2004-11-24, 08:50

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
×