cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
Showing results for 
Search instead for 
Did you mean: 

Community Tip - Have a PTC product question you need answered fast? Chances are someone has asked it before. Learn about the community search. X

Need help with the im command-line and arguments with <new-line>

smccoy
1-Newbie

Need help with the im command-line and arguments with <new-line>

Hi.

We are trying to create a utility that creates items with the 'im createissue" command from a DOS command-line. In this case it is a .bat file, but could be anything on the client-side. We're encountering errors when source data has embedded new-line characters, and we're wondering what the Integrity scripting engine does to handle new-line characters.

None of the on-line help or articles from Google searching have been helpful. We suspect that this is simple, once the trick is known.

A script that works:

var cmd = new Packages.com.mks.api.Command("im","createissue");

cmd.addOption( new Packages.com.mks.api.Option("type", "Functional Area") );

cmd.addOption( new Packages.com.mks.api.Option("field", "Summary=" + functionalAreaDescription));

if the variable functioalAreaDescription has a value with an embeded newline, the scripting engine handles things.

If we build the command in a .bat to be executed on the client it turns out:

im createissue --type="Functional Area" --fields="Summary=some data

the other data"

And the DOS command parser considers this 2 commands and yields errors. We can translate the embedded newline in to some harmless character, but we lose the "newline. The internal command processor will perform the command and preserve the newline.What the 'special trick' that the Integrity execution engine is using that preserves the newline and follows the proper command-line syntax.

Please advise.

-Sean

3 REPLIES 3
KaelLizak
14-Alexandrite
(To:smccoy)

Hello Sean,

Just to clarify, what I think you are saying is that you have a batch script that you want to have a Summary that looks something like this:

Some data

Other data

But when you try to enter it from the command line, every way you can think of to render a new-line breaks the command into two lines?

I'm going to quote myself from this other thread:

If you're trying to do this on a Windows workstation there is no trivial answer. As far as I can tell (I'm more of a Linux expert than a Windows expert) this is because there is no good way to escape the arguments. After some web searching, I believe these two articles seem to delve into this topic the best:

Fortunately, modern releases of Windows have a new CLI: PowerShell. If you try to do this in PowerShell, this should work:

integrity editmksdomaingroup --hostname=kvmcentos --user=kladmin --description="line1`r`nline2" analysts

If you're actually on a Unix-like workstation, this should be much easier. You should be able to do something like:

integrity editmksdomaingroup --hostname=kvmcentos --user=kladmin --description="`printf line1\nline2`" analysts

At least, I think you should. I haven't tested that.

So the option seem to be:

  • Use PowerShell scripts instead of batch files
  • Use a Unix shell such as sh, ksh, or bash
  • Use the API

If someone else has found a better way to do this, I would very much like to hear about it.

Regards,
Kael


Kind Regards,
Kael Lizak

Senior Technical Support Engineer
PTC Integrity Lifecycle Manager
mrump
14-Alexandrite
(To:smccoy)

Hi Sean,

just to be sure:

Your "Summary" field is a "longtext" field ?

If not, IMHO there will be no way to enter a newline via the commandline, as the underlying datamodel simply does not support such an entry. A "shorttext" field (like the "summary" field is in most solution) is always represented as a single line field; therefore all line breaks that might be enteres via a Copy/Paste Gesture or during an interactive use of the CLI are ignored.

If its is a "longtext" field IMHO you should be able to use default "\n" notation.

If it is even a richtext field (like the "description" field in most solutions), you should specifiy your content in a xhtml - format (using <br/> to force a line-break). The best way to learn would be if you take a look at the content of such a field for a given item. Just use "im viewissue --showRichContent <ID>" and review the result.

HTH Matthias

smccoy
1-Newbie
(To:mrump)

Thanks for the quick replies Kael, and Matthais.

The fields in question are longtext with Rich Content enabled. It works as expected through the Java-API, but there is a limitation with the command-line interface in Windows, and specifically .BAT files. Now that we have confirmed that, we will be able to find a suitable fix to get what we need.

-Sean

Top Tags