# Spawning processes from Ruby/TK

**URL:** <https://rubytalk.org/t/spawning-processes-from-ruby-tk/10076>\
**Category:** ruby-talk\
**Created:** [10 February 2004 02:22 UTC](https://rubytalk.org/t/spawning-processes-from-ruby-tk/10076 "2004-02-10T02:22:01Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Mehr\_Assaph\_Assaph](https://avatars.discourse-cdn.com/v4/letter/m/77aa72/32.png) [@Mehr\_Assaph\_Assaph](https://rubytalk.org/u/Mehr_Assaph_Assaph)\
**Post date:** [10 February 2004 02:22 UTC](https://rubytalk.org/t/spawning-processes-from-ruby-tk/10076/1 "2004-02-10T02:22:01Z")

</div>

Hi,

I need to launch an external process from a Tk app. I have a list-box of  
file names that should be processes as follows:

```
listbox.bind('Double-Button-1') {
    file = listbox.get(listbox.curselection)
    errors += `#{cmd % [file]}`
}

```

This causes a repeated error message:

C:\bin\cygwin\bin\ruby.exe: \*\*\* unable to remap  
C:\bin\cygwin\bin\tk84.dll to same address as parent(0x8C40000) !=  
0x8C50000  
4274332 [main] ruby 2584 sync\_with\_child: child 3260(0x280) died before  
initialization with status code 0x1  
4274659 [main] ruby 2584 sync\_with\_child: \*\*\* child state child loading  
dlls

So do ‘system’ and ‘IO.popen’ calls. ‘exec’ works, but of course  
terminates the app.  
Any ideas what’s wrong?

Cheers,  
Assaph

---

<div class="post-metadata">

**Author:** ![Hidetoshi\_NAGAI](https://avatars.discourse-cdn.com/v4/letter/h/49beb7/32.png) [@Hidetoshi\_NAGAI](https://rubytalk.org/u/Hidetoshi_NAGAI)\
**Post date:** [11 February 2004 15:41 UTC](https://rubytalk.org/t/spawning-processes-from-ruby-tk/10076/2 "2004-02-11T15:41:39Z")

</div>

Hi,

> **···**
>
> From: “Mehr, Assaph (Assaph)” [assaph@avaya.com](mailto:assaph@avaya.com)  
> Subject: spawning processes from Ruby/TK  
> Date: Tue, 10 Feb 2004 11:22:01 +0900  
> Message-ID: [338366A6D2E2CA4C9DAEAE652E12A1DE166D57@au3010avexu1.global.avaya.com](mailto:338366A6D2E2CA4C9DAEAE652E12A1DE166D57@au3010avexu1.global.avaya.com)
> 
> > I need to launch an external process from a Tk app. I have a list-box of  
> > file names that should be processes as follows:
> > 
> > ```
> > listbox.bind('Double-Button-1') {
> > file = listbox.get(listbox.curselection)
> > errors += `#{cmd % [file]}`
> > }
> > 
> > ```
> > 
> > This causes a repeated error message:
> 
> ## Which version of Ruby do you use? If you use 1.6.x, the problem maybe fixed on more recent versions. On my linux environment, 1.6.7 freezes and CVS Head completes properly.
> 
> ```
> Hidetoshi NAGAI (nagai@ai.kyutech.ac.jp)
> 
> ```

---

<div class="post-metadata">

**Author:** ![Vadim\_Konovalov](https://avatars.discourse-cdn.com/v4/letter/v/848f3c/32.png) [@Vadim\_Konovalov](https://rubytalk.org/u/Vadim_Konovalov)\
**Post date:** [11 February 2004 19:30 UTC](https://rubytalk.org/t/spawning-processes-from-ruby-tk/10076/3 "2004-02-11T19:30:00Z")

</div>

> I need to launch an external process from a Tk app. I have a list-box of  
> file names that should be processes as follows:
> 
> ```
> listbox.bind('Double-Button-1') {
> file = listbox.get(listbox.curselection)
> errors += `#{cmd % [file]}`
> }
> 
> ```

“unable to remap” is probably cygwin’s problem which has solution on its own

searching in cygwin gives result and here is “c” program for “rebase”

> **···**
>
> =================  
> /\*
> 
> - Copyright (c) 2001 Jason Tishler
> - 
> - This program is free software; you can redistribute it and/or
> - modify it under the terms of the GNU General Public License
> - as published by the Free Software Foundation; either version 2
> - of the License, or (at your option) any later version.
> - 
> - This program is distributed in the hope that it will be useful,
> - but WITHOUT ANY WARRANTY; without even the implied warranty of
> - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
> - GNU General Public License for more details.
> - 
> - You should have received a copy of the GNU General Public License
> - along with this program; if not, write to the Free Software
> - Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,  
> USA.
> - 
> - $Id: rebase.cc,v 1.5 2001/12/18 20:21:19 jtishler Exp $  
> \*/
> 
> #include   
> #include   
> #include   
> #include \<time.h\>  
> #include \<stdlib.h\>  
> #include \<getopt.h\>  
> #include \<sys/cygwin.h\>  
> #include \<windows.h\>  
> #include \<imagehlp.h\>
> 
> using namespace std;
> 
> string PosixToWin32(const string& aPosixPath);  
> void ParseArgs(int argc, char\* argv);  
> unsigned long StringToUlong(const string& aString);  
> void Usage();
> 
> ULONG theImageBase = 0;  
> BOOL theDownFlag = FALSE;  
> ULONG theOffset = 0;  
> int theArgsIndex = 0;
> 
> void  
> main(int argc, char\* argv)  
> {  
> ParseArgs(argc, argv);  
> ULONG aNewImageBase = theImageBase;
> 
> for (int i = theArgsIndex; i \< argc; i++)  
> {  
> if (theDownFlag)  
> aNewImageBase -= theOffset;
> 
> string aFile = PosixToWin32(argv[i]);  
> ULONG anOldImageSize, anOldImageBase, aNewImageSize;  
> ULONG aPrevNewImageBase = aNewImageBase;  
> BOOL aStatus = ReBaseImage(  
> const\_cast\<char\*\>(aFile.c\_str()), // CurrentImageName  
> 0, // SymbolPath  
> TRUE, // fReBase  
> FALSE, // fRebaseSysfileOk  
> theDownFlag, // fGoingDown  
> 0, // CheckImageSize  
> &anOldImageSize, // OldImageSize  
> &anOldImageBase, // OldImageBase  
> &aNewImageSize, // NewImageSize  
> &aNewImageBase, // NewImageBase  
> time(0)); // TimeStamp
> 
> // ReBaseImage seems to never returns false!  
> DWORD aStatus2 = GetLastError();  
> if (aStatus2 != 0)  
> {  
> cerr \<\< "ReBaseImage() failed with last error = " \<\<  
> GetLastError() \<\< endl;  
> exit(2);  
> }  
> cout \<\< aFile \<\< hex \<\< ": new base = " \<\<  
> ((theDownFlag) ? aNewImageBase : aPrevNewImageBase) \<\<  
> ", new size = " \<\< aNewImageSize + theOffset \<\< endl;
> 
> if (!theDownFlag)  
> aNewImageBase += theOffset;  
> }
> 
> exit(0);  
> }
> 
> string  
> PosixToWin32(const string& aPosixPath)  
> {  
> char aWin32Path[MAX\_PATH];  
> cygwin\_conv\_to\_win32\_path(aPosixPath.c\_str(), aWin32Path);  
> return aWin32Path;  
> }
> 
> void  
> ParseArgs(int argc, char\* argv)  
> {  
> const char\* anOptions = “b:do:”;  
> for (int anOption; (anOption = getopt(argc, argv, anOptions)) != -1;)  
> {  
> switch (anOption)  
> {  
> case ‘b’:  
> theImageBase = StringToUlong(optarg);  
> break;  
> case ‘d’:  
> theDownFlag = TRUE;  
> break;  
> case ‘o’:  
> theOffset = StringToUlong(optarg);  
> break;  
> default:  
> Usage();  
> exit(1);  
> break;  
> }  
> }
> 
> if (theImageBase == 0)  
> {  
> Usage();  
> exit(1);  
> }
> 
> theArgsIndex = optind;  
> }
> 
> unsigned long  
> StringToUlong(const string& aString)  
> {  
> stringstream ss;  
> unsigned long aUlong;  
> string::size\_type anIndex = aString.find(“0x”);  
> if (anIndex == 0)  
> ss \<\< hex \<\< string(aString, 2, aString.size() - 2);  
> else  
> ss \<\< aString;  
> ss \>\> aUlong;  
> return aUlong;  
> }
> 
> void  
> Usage()  
> {  
> cerr \<\< “usage: rebase -b BaseAddress [-d] -o Offset ImageFileName …” \<\<  
> endl;  
> }
> 
> =================
> 
> > This causes a repeated error message:
> > 
> > C:\bin\cygwin\bin\ruby.exe: \*\*\* unable to remap  
> > C:\bin\cygwin\bin\tk84.dll to same address as parent(0x8C40000) !=  
> > 0x8C50000  
> > 4274332 [main] ruby 2584 sync\_with\_child: child 3260(0x280) died before  
> > initialization with status code 0x1  
> > 4274659 [main] ruby 2584 sync\_with\_child: \*\*\* child state child loading  
> > dlls
