Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8110751
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T01:51:56+00:00 2026-06-06T01:51:56+00:00

I am trying to implement a gradle task to dynamically create a buildsignature.properties file

  • 0

I am trying to implement a gradle task to dynamically create a buildsignature.properties file from a series of environment variable values and shell executions. I have it mostly working, but I can’t seem to get the output of the shell commands. Here’s my task…

task generateBuildSignature << {
    ext.whoami = exec() {
        executable = "whoami"
    }
    ext.hostname = exec() {
         executable = "hostname"
    }
    ext.buildTag = System.env.BUILD_TAG ?: "dev"

    ant.propertyfile(
        file: "${buildDir}/buildsignature.properties",
        comment: "This file is automatically generated - DO NOT EDIT!" ) {
        entry( key: "version", value: "${project.version}" )
        entry( key: "buildTimestamp", value: "${new Date().format('yyyy-MM-dd HH:mm:ss z')}" )
        entry( key: "buildUser", value: "${ext.whoami}" )
        entry( key: "buildSystem", value: "${ext.hostname}" )
        entry( key: "buildTag", value: "$ext.buildTag" )
    }
}

But the resulting properties field does not get the desired results for buildUser and buildSystem.

#This file is automatically generated - DO NOT EDIT!
#Mon, 18 Jun 2012 18:14:14 -0700
version=1.1.0
buildTimestamp=2012-06-18 18\:14\:14 PDT
buildUser=org.gradle.process.internal.DefaultExecHandle$ExecResultImpl@2e6a54f9
buildSystem=org.gradle.process.internal.DefaultExecHandle$ExecResultImpl@46f0bf3d
buildTag=dev

How do I get buildUser and buildSystem to match the output of the corresponding exec rather than some default ExecResultImpl toString? This really can’t be that hard, can it?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-06T01:51:58+00:00Added an answer on June 6, 2026 at 1:51 am

    This post describes how to parse the output from an Exec invocation. Below you’ll find two tasks that run your commands.

    task setWhoamiProperty {
        doLast {
            new ByteArrayOutputStream().withStream { os ->
                def result = exec {
                    executable = 'whoami'
                    standardOutput = os
                }
                ext.whoami = os.toString()
            }
        }
    }
    
    task setHostnameProperty {
        doLast {
            new ByteArrayOutputStream().withStream { os ->
                def result = exec {
                    executable = 'hostname'
                    standardOutput = os
                }
                ext.hostname = os.toString()
            }
        }
    }
    
    task printBuildInfo {
        dependsOn setWhoamiProperty, setHostnameProperty
        doLast {
             println whoami
             println hostname
        }
    }
    

    There’s actually an easier way to get this information without having to invoke a shell command.

    Currently logged in user: System.getProperty('user.name')

    Hostname: InetAddress.getLocalHost().getHostName()

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Am trying to implement a generic way for reading sections from a config file.
Trying to implement a search similar to here .This searches properties based on city,locality,property
Trying to implement the decorator pattern in C# from the code in the Head
I am trying implement Unblock me Puzzle. i want to change image position from
I'm trying implement Data Annotation to my Linq to SQL objects. The .dbml file
trying to implement a multiplayer. Using the sample from Game Center - Sending and
Trying to implement a shell, mainly piping. I've written this test case which I
Trying to implement the example from here. Facebook Share passes along the URL of
Im trying to implement a save feature to save an html file. Currently it
I'm trying to implement the code from showing dialog while loading layout by setContentView

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.