- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Get Direct Link
- Report Inappropriate Content
Please help me remove carriage character in JSL
I have a jsl script which calls python file to identify a specific directory from anywhere. It is working fine but he result has a carriage character which is ruining everything.
cur_dir = Substr( Get Default Directory(), 2, 999 );
cur_dir = Substitute( cur_dir, "/", "\" );
show(cur_dir);
_path_script = cur_dir || "find_home_directory.py";
show(_path_script);
home_dir = RunProgram(
executable( "python" ),
options( _path_script),
readfunction( "text" )
);
show(home_dir);
home_dir = "C:\dtemp
";
Anyone , can you please help me how to convert this string to remove the carriage character and looks like this?
home_dir = "C:\dtemp"
Accepted Solutions
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Get Direct Link
- Report Inappropriate Content
Re: Please help me remove carriage character in JSL
@pmroz's solution is a good one! Here is a general reference to the common invisible characters that might appear in a string of characters. You can use the escape sequence to search.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Get Direct Link
- Report Inappropriate Content
Re: Please help me remove carriage character in JSL
cr = "
";
home_dir = "C:\dtemp
";
home_dir = substitute(home_dir, cr, "");
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Get Direct Link
- Report Inappropriate Content
Re: Please help me remove carriage character in JSL
cur_dir = Substr( Get Default Directory(), 2, 999 );
cur_dir = Substitute( cur_dir, "/", "\" );
show(cur_dir);
_path_script = cur_dir || "find_home_directory.py";
show(_path_script);
home_dir = RunProgram(
executable( "python" ),
options( _path_script),
readfunction( "text" )
);
show(home_dir);
cr ="
";
home_dir = substitute(home_dir, cr, "");
show(home_dir);
Result is still the same..:(
home_dir = "C:\dekel_post_processing
";
home_dir = "C:\dekel_post_processing
";
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Get Direct Link
- Report Inappropriate Content
Re: Please help me remove carriage character in JSL
Although it works if you just run this few lines individually.
cr = "
";
home_dir = "C:\dtemp
";
show(home_dir);
home_dir = substitute(home_dir, cr, "");
show(home_dir);
Result:
home_dir = "C:\dtemp
";
home_dir = "C:\dtemp";
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Get Direct Link
- Report Inappropriate Content
Re: Please help me remove carriage character in JSL
Here is how I would do it using the standard escape characters in JMP
names default to here(1);
cr = "\!r";
home_dir = "C:\dtemp
";
show(home_dir);
home_dir = substitute(home_dir, cr, "");
show(home_dir);
Which gave the reslts
home_dir = "C:\dtemp "; home_dir = "C:\dtemp";
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Get Direct Link
- Report Inappropriate Content
Re: Please help me remove carriage character in JSL
@pmroz's solution is a good one! Here is a general reference to the common invisible characters that might appear in a string of characters. You can use the escape sequence to search.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Get Direct Link
- Report Inappropriate Content
Re: Please help me remove carriage character in JSL
I tried it with "(\r)" as RegEx search but still getting the same issue.
cur_dir = Substr( Get Default Directory(), 2, 999 );
cur_dir = Substitute( cur_dir, "/", "\" );
show(cur_dir);
_path_script = cur_dir || "find_home_directory.py";
show(_path_script);
home_dir = RunProgram(
executable( "python" ),
options( _path_script),
readfunction( "text" )
);
show(home_dir);
cr = Regex(home_dir,"(\r)");
home_dir = substitute(home_dir, cr, "");
show(home_dir);
Result.
home_dir = "C:\tmp
";
home_dir = "C:\tmp
";
What I want:
home_dir = "C:\tmp"
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Get Direct Link
- Report Inappropriate Content
Re: Please help me remove carriage character in JSL
Maybe this?
cur_dir = Substr( Get Default Directory(), 2 );
cur_dir = Convert File Path( cur_dir, Windows );
Show( cur_dir );
_path_script = cur_dir || "find_home_directory.py";
Show( _path_script );
home_dir = Run Program( executable( "python" ), options( _path_script ), readfunction( "text" ) );
Show( home_dir );
home_dir = Substitute( home_dir, "\r", "" );
Show( home_dir );
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Get Direct Link
- Report Inappropriate Content
Re: Please help me remove carriage character in JSL
yup finally it worked. The trick is following:
suppose you have a file "example.jsl" and you want to have the absolute path. You should do following:
cur_dir = Substr( Get Default Directory(), 2 );
cur_dir = Convert File Path( cur_dir, Windows );
Show( cur_dir );
_path_script = cur_dir || "find_home_directory.py";
Show( _path_script );
home_dir = Run Program( executable( "python" ), options( _path_script ), readfunction( "text" ) );
Show( home_dir );
path_to_example_jsl = Substitute( home_dir, "\r", "example.jsl" );
Show( path_to_example_jsl );
The python file you call is simple:
import os
def find_home_dir():
cur_dir = os.path.dirname(os.path.realpath(__file__))
while True:
if "file_which_defines_root" in os.listdir(cur_dir):
break
else:
cur_dir = os.path.dirname(cur_dir)
print(cur_dir.strip())
if __name__ == '__main__':
find_home_dir()