Results 1 to 5 of 5

Thread: Executable & libraries in one folder, but force it's output into different folder

  1. #1
    Join Date
    Oct 2012
    Location
    Geekland
    Beans
    Hidden!
    Distro
    Kubuntu

    Executable & libraries in one folder, but force it's output into different folder

    I have a set of binaries, 2 regular and 3+ libraries. Some libraries are in sub-folders. I want to launch the main binary in such a way that it places any files it creates into a folder above it. Here is a generic layout before and after the run.

    Before:
    BaseDir


    exec

    lib1.so

    libDir


    library1a.so


    library1b.so

    textfile.txt
    OtherDir


    After (how it is now):
    BaseDir


    exec

    lib1.so

    libDir


    library1a.so


    library1b.so

    textfile.txt

    someDir


    generatedFile.txt

    otherGeneratedFile.txt
    OtherDir


    After (how I want it):
    BaseDir


    exec

    lib1.so

    libDir


    library1a.so


    library1b.so

    textfile.txt
    OtherDir


    someDir


    generatedFile.txt

    otherGeneratedFile.txt


    So, how can I launch it in such a way that it writes/reads generated files/folders to 'OtherDir', but still use the libraries and run the other executable (which is in a sub-directory of 'BaseDir') without linking the entire contents of 'BaseDir' into 'OtherDir'. I just so everyone knows: this is a closed source and commercial program that, with the permission of the developers, I am making a deb package for. The files it generates are databases and uploaded content, of which would get destroyed on an upgrade - I did it without backing up the folder and poof...

    Sincerely,
    Patrick Thomas (Timberwolf)


  2. #2
    Join Date
    Aug 2011
    Location
    47°9′S 126°43W
    Beans
    2,172
    Distro
    Ubuntu 16.04 Xenial Xerus

    Re: Executable & libraries in one folder, but force it's output into different folder

    The setup is totally non-Unixish. Even on Windows now it's a capital sin to mix user data and executable code in the same directories.... if only because as you saw this often puts your data in jeopardy.

    You don't tell us why it writes files in specific directories. Is it because it is the current directory when it starts? Or because it finds it using the location of the executable itself? If the latter there are likely ways to trick it using links in the proper directories. Typically you would set up a directory for data and put in it links to the executable files installed elsewhere. This way you can put th executable files in a public place, and keep the data separately (and each user with his own set of data). Of course you would start the application using the "user" links.
    Warning: unless noted otherwise, code in my posts should be understood as "coding suggestions", and its use may require more neurones than the two necessary for Ctrl-C/Ctrl-V.

  3. #3
    Join Date
    Oct 2012
    Location
    Geekland
    Beans
    Hidden!
    Distro
    Kubuntu

    Re: Executable & libraries in one folder, but force it's output into different folder

    Quote Originally Posted by ofnuts View Post
    The setup is totally non-Unixish. Even on Windows now it's a capital sin to mix user data and executable code in the same directories.... if only because as you saw this often puts your data in jeopardy.
    If only it was punishable

    Quote Originally Posted by ofnuts View Post
    You don't tell us why it writes files in specific directories. Is it because it is the current directory when it starts? Or because it finds it using the location of the executable itself? If the latter there are likely ways to trick it using links in the proper directories.
    I didn't say because I don't know... Let me cd to the external directory and maybe run it using the relative path.
    UPDATE: Running it with a relative path made it balk because it did not find the libs.
    UPDATE 2: Tried linking the libraries, but it still complained.
    UPDATE 3: I had an idea, but it just seems so sloppy... I could run it, kill it, move the generated files, and symlink them back...

    Quote Originally Posted by ofnuts View Post
    Typically you would set up a directory for data and put in it links to the executable files installed elsewhere. This way you can put the executable files in a public place, and keep the data separately (and each user with his own set of data). Of course you would start the application using the "user" links.
    Unfortunately, they didn't do it that way. As stupid as it is... And BTW those files are system wide, as it is a service that provides a server.
    Last edited by wolfgentleman; August 9th, 2014 at 07:54 PM.

    Sincerely,
    Patrick Thomas (Timberwolf)


  4. #4
    Join Date
    Aug 2011
    Location
    47°9′S 126°43W
    Beans
    2,172
    Distro
    Ubuntu 16.04 Xenial Xerus

    Re: Executable & libraries in one folder, but force it's output into different folder

    Quote Originally Posted by wolfgentleman View Post
    If only it was punishable
    It is punished. Misbehaving software like this gets bad press. Sooner or later is means some sale going to the competition (which could come from some developer fed up with their stuff and deciding to make his own).

    Quote Originally Posted by wolfgentleman View Post
    Unfortunately, they didn't do it that way. As stupid as it is...
    If they are really interested in getting a .deb, then they could tell you how they locate the files and then you could devise some way to keep them happy. Otherwise, they aren't interested in having a .deb, in which case see my remark above.
    Warning: unless noted otherwise, code in my posts should be understood as "coding suggestions", and its use may require more neurones than the two necessary for Ctrl-C/Ctrl-V.

  5. #5
    Join Date
    Jun 2007
    Location
    Maryland, US
    Beans
    6,288
    Distro
    Kubuntu

    Re: Executable & libraries in one folder, but force it's output into different folder

    Just write a script to take care of the undesirable nuances of the executable program. For example:

    Code:
    #!/bin/bash
    
    LD_LIBRARY_PATH=$PWD:$PWD/libDir ./exec
    
    if [ $? -eq 0 ]; then
        mv someDir otherDir
        mv otherGeneratedFile.txt otherDir
    fi

Tags for this Thread

Bookmarks

Posting Permissions

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