java stream redirection - create path if it does not exist - Advanced Installer Community

We’re moving our forums to a new platform.

You can still browse and search existing topics, but you can no longer create new topics or post replies.

For questions, technical issues, or feature requests, please don’t hesitate to contact our support team at support@advancedinstaller.com.

Thank you for your understanding!

toddpatt
Posts: 111
Joined: Fri Jan 08, 2010 1:36 am

java stream redirection - create path if it does not exist

G'day,

I am using AI 7.6 build 27499

I have a per-machine (installation type) java project for which I have enabled the stream redirection option. The information contained in the output streams is very user-specific, and so I would like to write this data to the APPDATA folder of the current user. To achieve this, I have configured the stream redirection as such:
Out: "%APPDATA%\[Manufacturer]\[ProductName]\output.log"
Err: "%APPDATA%\[Manufacturer]\[ProductName]\error.log"

The problem is that if the "[Manufacturer]\[ProductName]" sub-folders do not exist, the native java launcher does not create them and thus the log files are never created either. Is it possible for the native launcher to create sub-folders if they do not yet exist?

After building and installing my project, if I edit the .ini file and change the stream redirect paths to "%APPDATA%\output.log" and "%APPDATA%\error.log", the log files are then created and populated as expected.

At first, I thought that I could solve this problem by creating the "[Manufacturer]\[ProductName]" sub-folders as part of the install. That approach will work for the user who performed the install, but only for that user. If the machine is shared by several users, and those other users run the app, they will not have any "[Manufacturer]\[ProductName]" sub-folders in their APPDATA folder.

I don't think changing the project "Installation Type" will help either. The installer cannot know all of the users who may run the app, and so it seems the only way to solve this problem is to dynamically create the "[Manufacturer]\[ProductName]" sub-folders as necessary when the app runs.

I understand that the ability to create new folders at run-time may be restricted due to permissions (if the stream redirect path was pointed to a restricted folder), but for my APPDATA situation it should succeed.

Any help you can offer would be greatly appreciated!

thanks much,
-Todd
GabrielBarbu
Posts: 2146
Joined: Thu Jul 09, 2009 11:24 am
Contact: Website

Re: java stream redirection - create path if it does not exist

Hello,

You can try the following:
- create the log folder in the common application data folder through the Files and Folders page
- create a file removal operation there so the logs are deleted when your package is uninstalled
- on the Java Products page->Virtual Machine tab, set the redirected streams to files containing the username in the file name, so a different log file will be created for each user

Let me know if this helped.

Attached is a sample project demonstrating my suggestion.

Best regards,
Gabriel
Attachments
sample.aip
(12.64 KiB) Downloaded 442 times
Gabriel Barbu
Advanced Installer Team
http://www.advancedinstaller.com/
toddpatt
Posts: 111
Joined: Fri Jan 08, 2010 1:36 am

Re: java stream redirection - create path if it does not exist

Thanks for providing the sample, Gabriel. I configured my project as you advised and it works fine - the logs are created for each user and the uninstall clean-up removes them.

I can use this alternative solution for now, but it would ultimately be best to store these logs in the APPDATA folder for each user. The "Common Application Data" folder is not typically used for logging.

I found a forum post from 2007, where another user also wants to redirect the java err/out streams to the AppDataFolder for each user. At the end of the thread, Cosmin said "this feature will be available in a future version of Advanced Installer". Is there still an open issue/improvement for this request that you guys are tracking? I can tell from the amount of activity on the forum that you guys are extremely busy, but it would really be nice to see this minor improvement implemented. If there is an open issue, could you perhaps add a comment/pointer to our conversation here?

Thanks for your help - very much appreciated.
-Todd
Bogdan
Posts: 2796
Joined: Tue Jul 07, 2009 7:34 am
Contact: Website

Re: java stream redirection - create path if it does not exist

Hi Todd,

We could easily create that path, just as you requested without being forced to use the workaround suggested by Gabriel.

BUT, there is a drawback to this solution, that is why we keep recommending the solution presented by Gabriel. What happens is that
there is no possibility to delete the created locations upon uninstall, therefore the user will remain with garbage on its machine after
uninstalling the application, the files and folders from those locations will not be removed.

Regards,
Bogdan
Bogdan Mitrache - Advanced Installer Team
Follow us: Twitter - Facebook - YouTube
toddpatt
Posts: 111
Joined: Fri Jan 08, 2010 1:36 am

Re: java stream redirection - create path if it does not exist

Hey Bogdan - thanks for your reply.

I understand the concern about removing the redirect logs at uninstall.

However, when my application runs it is writing data to the current user's AppData folder. The type of data is user-preferences and statistical reports derived from the current user's email account, so it is very personal data which should not be put in a common folder like "Common Application Data". In my opinion, the user's AppData folder was designed for this very purpose - storing personal information generated by applications.

I am then removing this personal data via an AI Uninstall Clean-Up task. I have tested this and the uninstall clean-up task deletes files and folders from the current user's AppData folder. Yes, I realize this type of configuration can leave behind "garbage" in other user's AppData folder (if they also ran the application at some point), but my product-manager actually prefers that behavior. The idea is that if both User-1 and User-2 have used the application (assume it was installed per-machine), and User-2 decides he no longer wants the app and thus uninstalls it, only User-2's data is removed. If User-1 says "Hey! I was still using that app, I want it back!" and reinstalls, User-1 still has his data and customizations.

In that sense, the user's AppData\[Manufacturer]\[ProductName] folder is his working directory. Just as the user's preferences and generated data are written there, I would like to write the redirect logs there. When the current user uninstalls, data and logs from only his AppData folder are removed. I realize that it may not be "best practice" to leave behind data generated by my app, but that is one way to preserve user preferences and customizations...

Hopefully it makes more sense now why I want to write the redirect logs to the AppData folder.
Having that flexibility in AI would be fantastic :)

thanks,
-Todd
GabrielBarbu
Posts: 2146
Joined: Thu Jul 09, 2009 11:24 am
Contact: Website

Re: java stream redirection - create path if it does not exist

Hello Todd,

I have added a new improvement on our TODO list that will enable the java wrapper to create the directories for you.
The improvement will be implemented in a future version of Advanced Installer.

Best regards,
Gabriel
Gabriel Barbu
Advanced Installer Team
http://www.advancedinstaller.com/
toddpatt
Posts: 111
Joined: Fri Jan 08, 2010 1:36 am

Re: java stream redirection - create path if it does not exist

Thanks very much, Gabriel. I will look for this improvement in future versions.

-Todd

Return to “Common Problems”